Home Help Center

How to pass value into servant locator instance?

fabwarefabware Member can xiangOrganization: fabware software Ltd.Project: order managment and inventory control
Hi,

I'm using Ice-3.3.1 with python. My knowledge of ICE is about ice core, glacier2.

My application data is stored in different databases by different group of users. So servant locator is my direct option to load servant from database record. And I use glacier2 session to identify different users.
class SessionManagerI(Glacier2.SessionManager):
    
    def __init__(self):
        Glacier2.SessionManager.__init__(self)
        
    def create(self, userId, control=None, current=None):
        session = SessionI(userId)

        inquiry_locator = InquiryLocatorI(session)
        current.adapter.addServantLocator(inquiry_locator, 'Inquiry')

        return Glacier2.SessionPrx.uncheckedCast(current.adapter.addWithUUID(session))

The above code says what I want and clearly the servant locator shouldn't be added to adapter in SessionManager instead of in main.

The problem is here, I want to locate inquiry object by session, because the session knows which database to connect and which user to attach onto the located servant(the servant should be know how to behave by different user attached to it).

Well, I can't do this because adapter.addServantLocator should be called only once for a given category. So, I can't pass session value into a locator instance on the fly.

What's the solution to this kind of problem.

Best regards!
can

Comments

  • matthewmatthew NL, CanadaMember Matthew NewhookOrganization: ZeroC, Inc.Project: Internet Communications Engine ✭✭✭
    Sorry, its not clear what you want to do. At any rate, what you would typically do is lookup the user at the time of session creation, and cache the user information in the session. All backend access would go through the session object. This has the advantage of making your backend security simple (there is only one point of access), and establishing a tight contract with your backend server clients.
  • fabwarefabware Member can xiangOrganization: fabware software Ltd.Project: order managment and inventory control
    Servant Locator seems not the solution

    Hi, matthew

    Thanks for your suggestion even I don't make it clear enough. Yes, I currently use glacier2 session to remember the user and you just make it clear that servant locator is a second entry point which I should avoid (it will skip security check).

    My specific problem related with two situation:
    1. The server will serve different group of users, each group owns their own database.
    2. Each servant may contain operation that need specific permission of the user.

    I thought servant locator maybe the right answer to load massive database record, so I was trying to make session object available into the servant locator, which I finally found out impossible. It seems value should be pass into servant locator only from identity.

    So, I think every thing would go into session interfaces. What a pitty servant locator can't be used, it's just such a good idea to the database problem. There is no easy option for me to do that.

    Thanks again matthew, teach me if I missed something.

    Best regards!
    Can
  • matthewmatthew NL, CanadaMember Matthew NewhookOrganization: ZeroC, Inc.Project: Internet Communications Engine ✭✭✭
    Its not impossible to access the session from the servant locator. If you really need to do that, you'd need to use a lookup table to access the session for a given user. If the locator and session are always co-located, then a simple map would do, otherwise you'd need a lookup service.
  • fabwarefabware Member can xiangOrganization: fabware software Ltd.Project: order managment and inventory control
    thanks

    Hi, matthew

    Thanks for your really prompt reply.

    Yes, makeup an identity with "group_id-user_id-inquiry" category and "inquiry_id" name will successfully get the servant. For me the session may only preserve the corresponding user and group, so it's even unnecessarily make a lookup. Because the proxy is provided by a session, so it wouldn't be a problem regarding security.

    The only thing left for me is implement it and see which way is better.

    Thanks and Best regards!
    Can
Sign In or Register to comment.