/** @return An Ice Identity for this datatype category and the data provided */ public static Identity createIdentity( String userEmail, int tripId, uclm.esi.cardroid.data.zerocice.ActivityType activityType, long timeStamp) { Identity id = new Identity(); id.category = "user_activity"; id.name = userEmail + "@" + tripId + "[" + activityType.name() + " " + timeStamp + "]"; return id; }
/** * SessionController constructor method * * @param handler Handler for posting event messages * @param communicator The communicator the session operates on * @param session The SessionAdapter managing this session * @param refreshTimeout The period on which the session will be refreshed to avoid its * destruction due the lack of activity in the client, expressed in milliseconds */ public SessionController( Handler handler, Communicator communicator, SessionAdapter session, long refreshTimeout) { _communicator = communicator; _session = session; _handler = handler; /* Initialize and start the thread responsible for refreshing the * * user session on the server */ _refresh = new SessionRefreshThread(refreshTimeout); _refresh.start(); /* Initialize the QueryController used to query the server * * (by means of the public operational interface provided) */ _queryController = new DBQueryController(_handler, _session.getCardroidManager()); // Setup the event monitor servant Identity eventStormId = new Identity(); eventStormId.name = UUID.randomUUID().toString(); Ice.RouterPrx r = _communicator.getDefaultRouter(); /* Create an object adapter from the user session's Communicator, * * attending to whether it makes use of a router to redirect the * * data it carries. This will be the object adapter for the client, * * responsible for providing incarnations to the proxies received * * from the server which may require it */ if (r != null) { Glacier2.RouterPrx router = Glacier2.RouterPrxHelper.checkedCast(r); _adapter = _communicator.createObjectAdapterWithRouter("CardroidClient", router); eventStormId.category = router.getCategoryForClient(); } else { _adapter = _communicator.createObjectAdapter("CardroidClient"); eventStormId.category = ""; } /* Add a ServantLocator to the client's ObjectAdapter for every * * object category, mapping them to the corresponding datatypes, * * implemented on object classes. Whenever a proxy is added to the * * client's ObjectAdapter, a servant incarnating the object * * referenced by such a proxy will be created */ _adapter.addServantLocator(new LocatorI(new Place()), "place"); _adapter.addServantLocator(new LocatorI(new Car()), "car"); _adapter.addServantLocator(new LocatorI(new User()), "user"); _adapter.addServantLocator(new LocatorI(new Trip()), "trip"); _adapter.addServantLocator(new LocatorI(new TripOffer(this)), "trip_offer"); _adapter.addServantLocator(new LocatorI(new TripRequest(this)), "trip_request"); _adapter.addServantLocator(new LocatorI(new UserActivity(this)), "user_activity"); _adapter.addServantLocator(new LocatorI(new Message(this)), "message"); /* Add an ObjectFactory for each of the domain class datatypes the * * session's Communicator will make use of. Whenever the IceRuntime * * needs to instantiate a class characterized by an ID, it will call * * the create(String) method of the ObjectFactory registered along * * with such an ID */ _communicator.addObjectFactory(new Car(), Car.ice_staticId()); _communicator.addObjectFactory(new Date(), Date.ice_staticId()); _communicator.addObjectFactory(new DateTime(), DateTime.ice_staticId()); _communicator.addObjectFactory(new DateTimePrefs(), DateTimePrefs.ice_staticId()); _communicator.addObjectFactory(new Message(this), Message.ice_staticId()); _communicator.addObjectFactory(new Passenger(this), Passenger.ice_staticId()); _communicator.addObjectFactory(new Place(), Place.ice_staticId()); _communicator.addObjectFactory(new Trip(), Trip.ice_staticId()); _communicator.addObjectFactory(new TripOffer(this), TripOffer.ice_staticId()); _communicator.addObjectFactory(new TripRequest(this), TripRequest.ice_staticId()); _communicator.addObjectFactory(new User(), User.ice_staticId()); _communicator.addObjectFactory(new UserActivity(this), UserActivity.ice_staticId()); _communicator.addObjectFactory(new Waypoint(), Waypoint.ice_staticId()); // Add the event monitor object to this client's ObjectAdapter _eventProxy = CardroidEventStormPrxHelper.uncheckedCast( _adapter.add(new CardroidEventStormI(), eventStormId)); _adapter.activate(); /* Associate the Connection used by this user session's * * CardroidManager instance with this client's ObjectAdapter, * * in order to enable a bidirectional connection */ session.getCardroidManager().ice_getConnection().setAdapter(_adapter); // Subscribe the event monitor to the user's topic try { session.subscribeTopic(_eventProxy); } catch (AlreadySubscribed as) { // Already subscribed to topic } setupMyUser(); }