def registration_list(self): """ List current registrations. :returns: A dictionary with three entries for the match policies 'exact', 'prefix' and 'wildcard', with a list of registration IDs for each. :rtype: dict """ registration_map = self._router._dealer._registration_map registrations_exact = [] for registration in registration_map._observations_exact.values(): if not is_protected_uri(registration.uri): registrations_exact.append(registration.id) registrations_prefix = [] for registration in registration_map._observations_prefix.values(): if not is_protected_uri(registration.uri): registrations_prefix.append(registration.id) registrations_wildcard = [] for registration in registration_map._observations_wildcard.values(): if not is_protected_uri(registration.uri): registrations_wildcard.append(registration.id) return { 'exact': registrations_exact, 'prefix': registrations_prefix, 'wildcard': registrations_wildcard, }
def subscription_list(self, session_id=None, details=None): """ List current subscriptions. :returns: A dictionary with three entries for the match policies 'exact', 'prefix' and 'wildcard', with a list of subscription IDs for each. :rtype: dict """ if session_id: s2s = self._router._broker._session_to_subscriptions session = None if session_id in self._router._session_id_to_session: session = self._router._session_id_to_session[session_id] if is_restricted_session(session): session = None if not session or session not in s2s: raise ApplicationError( ApplicationError.NO_SUCH_SESSION, u'no session with ID {} exists on this router'.format(session_id), ) _subs = s2s[session] subs = { u'exact': [sub.id for sub in _subs if sub.match == u'exact'], u'prefix': [sub.id for sub in _subs if sub.match == u'prefix'], u'wildcard': [sub.id for sub in _subs if sub.match == u'wildcard'], } return subs else: subscription_map = self._router._broker._subscription_map subscriptions_exact = [] for subscription in subscription_map._observations_exact.values(): if not is_protected_uri(subscription.uri, details): subscriptions_exact.append(subscription.id) subscriptions_prefix = [] for subscription in subscription_map._observations_prefix.values(): if not is_protected_uri(subscription.uri, details): subscriptions_prefix.append(subscription.id) subscriptions_wildcard = [] # FIXME # for subscription in subscription_map._observations_wildcard.values(): # if not is_protected_uri(subscription.uri, details): # subscriptions_wildcard.append(subscription.id) subs = { u'exact': subscriptions_exact, u'prefix': subscriptions_prefix, u'wildcard': subscriptions_wildcard, } return subs
def subscription_list(self): """ List current subscriptions. :returns: A dictionary with three entries for the match policies 'exact', 'prefix' and 'wildcard', with a list of subscription IDs for each. :rtype: dict """ subscription_map = self._router._broker._subscription_map subscriptions_exact = [] for subscription in subscription_map._observations_exact.values(): if not is_protected_uri(subscription.uri): subscriptions_exact.append(subscription.id) subscriptions_prefix = [] for subscription in subscription_map._observations_prefix.values(): if not is_protected_uri(subscription.uri): subscriptions_prefix.append(subscription.id) subscriptions_wildcard = [] for subscription in subscription_map._observations_wildcard.values(): if not is_protected_uri(subscription.uri): subscriptions_wildcard.append(subscription.id) return { 'exact': subscriptions_exact, 'prefix': subscriptions_prefix, 'wildcard': subscriptions_wildcard, }
def registration_list(self, session_id=None, details=None): """ List current registrations. :returns: A dictionary with three entries for the match policies 'exact', 'prefix' and 'wildcard', with a list of registration IDs for each. :rtype: dict """ if session_id: s2r = self._router._dealer._session_to_registrations session = None if session_id in self._router._session_id_to_session: session = self._router._session_id_to_session[session_id] if is_restricted_session(session): session = None if not session or session not in s2r: raise ApplicationError( ApplicationError.NO_SUCH_SESSION, u'no session with ID {} exists on this router'.format(session_id), ) _regs = s2r[session] regs = { u'exact': [reg.id for reg in _regs if reg.match == u'exact'], u'prefix': [reg.id for reg in _regs if reg.match == u'prefix'], u'wildcard': [reg.id for reg in _regs if reg.match == u'wildcard'], } return regs else: registration_map = self._router._dealer._registration_map registrations_exact = [] for registration in registration_map._observations_exact.values(): if not is_protected_uri(registration.uri, details): registrations_exact.append(registration.id) registrations_prefix = [] for registration in registration_map._observations_prefix.values(): if not is_protected_uri(registration.uri, details): registrations_prefix.append(registration.id) registrations_wildcard = [] for registration in registration_map._observations_wildcard.values(): if not is_protected_uri(registration.uri, details): registrations_wildcard.append(registration.id) regs = { u'exact': registrations_exact, u'prefix': registrations_prefix, u'wildcard': registrations_wildcard, } return regs
def subscription_list_subscribers(self, subscription_id, details=None): """ Retrieve list of subscribers (WAMP session IDs) subscribed on (attached to) a subscription. :param subscription_id: The ID of the subscription to get subscribers for. :type subscription_id: int :returns: A list of WAMP session IDs of subscribers currently attached to the subscription. :rtype: list """ subscription = self._router._broker._subscription_map.get_observation_by_id( subscription_id) if subscription: if is_protected_uri(subscription.uri, details): raise ApplicationError( ApplicationError.NOT_AUTHORIZED, message= 'not authorized to list subscribers for protected URI "{}"' .format(subscription.uri), ) session_ids = [] for subscriber in subscription.observers: session_ids.append(subscriber._session_id) return session_ids else: raise ApplicationError( ApplicationError.NO_SUCH_SUBSCRIPTION, 'no subscription with ID {} exists on this broker'.format( subscription_id), )
def registration_list_callees(self, registration_id, details=None): """ Retrieve list of callees (WAMP session IDs) registered on (attached to) a registration. :param registration_id: The ID of the registration to get callees for. :type registration_id: int :returns: A list of WAMP session IDs of callees currently attached to the registration. :rtype: list """ registration = self._router._dealer._registration_map.get_observation_by_id( registration_id) if registration: if is_protected_uri(registration.uri, details): raise ApplicationError( ApplicationError.NOT_AUTHORIZED, message= 'not authorized to list callees for protected URI "{}"'. format(registration.uri), ) session_ids = [] for callee in registration.observers: session_ids.append(callee._session_id) return session_ids else: raise ApplicationError( ApplicationError.NO_SUCH_REGISTRATION, 'no registration with ID {} exists on this dealer'.format( registration_id), )
def subscription_match(self, topic, details=None): """ Given a topic URI, returns all subscriptions matching the topic. This essentially models what a broker does for dispatching an incoming publication. :param topic: The topic to match. :type topic: str :returns: All matching subscriptions or ``None``. :rtype: obj or None """ subscriptions = self._router._broker._subscription_map.match_observations( topic) if subscriptions: subscription_ids = [] for subscription in subscriptions: if not is_protected_uri(subscription.uri, details): subscription_ids.append(subscription.id) if subscription_ids: return subscription_ids else: return None else: return None
def subscription_get(self, subscription_id, details=None): """ Get subscription details. :param subscription_id: The ID of the subscription to retrieve. :type subscription_id: int :returns: The subscription details. :rtype: dict """ subscription = self._router._broker._subscription_map.get_observation_by_id( subscription_id) if subscription: if is_protected_uri(subscription.uri, details): raise ApplicationError( ApplicationError.NOT_AUTHORIZED, message= 'not authorized to get subscription for protected URI "{}"' .format(subscription.uri), ) subscription_details = { 'id': subscription.id, 'created': subscription.created, 'uri': subscription.uri, 'match': subscription.match, } return subscription_details else: raise ApplicationError( ApplicationError.NO_SUCH_SUBSCRIPTION, 'no subscription with ID {} exists on this broker'.format( subscription_id), )
def subscription_count_subscribers(self, subscription_id, details=None): """ Retrieve number of subscribers subscribed on (attached to) a subscription. :param subscription_id: The ID of the subscription to get the number subscribers for. :type subscription_id: int :returns: Number of subscribers currently attached to the subscription. :rtype: int """ subscription = self._router._broker._subscription_map.get_observation_by_id( subscription_id) if subscription: if is_protected_uri(subscription.uri, details): raise ApplicationError( ApplicationError.NOT_AUTHORIZED, message= 'not authorized to count subscribers for protected URI "{}"' .format(subscription.uri), ) return len(subscription.observers) else: raise ApplicationError( ApplicationError.NO_SUCH_SUBSCRIPTION, 'no subscription with ID {} exists on this broker'.format( subscription_id), )
def registration_get(self, registration_id, details=None): """ Get registration details. :param registration_id: The ID of the registration to retrieve. :type registration_id: int :returns: The registration details. :rtype: dict """ registration = self._router._dealer._registration_map.get_observation_by_id(registration_id) if registration: if is_protected_uri(registration.uri, details): raise ApplicationError( ApplicationError.NOT_AUTHORIZED, message=u'not authorized to get registration for protected URI "{}"'.format(registration.uri), ) registration_details = { u'id': registration.id, u'created': registration.created, u'uri': registration.uri, u'match': registration.match, u'invoke': registration.extra.invoke, } return registration_details else: raise ApplicationError( ApplicationError.NO_SUCH_REGISTRATION, u'no registration with ID {} exists on this dealer'.format(registration_id), )
def registration_count_callees(self, registration_id, details=None): """ Retrieve number of callees registered on (attached to) a registration. :param registration_id: The ID of the registration to get the number of callees for. :type registration_id: int :returns: Number of callees currently attached to the registration. :rtype: int """ registration = self._router._dealer._registration_map.get_observation_by_id( registration_id) if registration: if is_protected_uri(registration.uri, details): raise ApplicationError( ApplicationError.NOT_AUTHORIZED, message= u'not authorized to count callees for protected URI "{}"'. format(registration.uri), ) return len(registration.observers) else: raise ApplicationError( ApplicationError.NO_SUCH_REGISTRATION, u'no registration with ID {} exists on this dealer'.format( registration_id), )
def subscription_remove_subscriber(self, subscription_id, subscriber_id, reason=None): """ Forcefully remove subscriber from subscription. :param subscription_id: The ID of the subscription to remove the subscriber from. :type subscription_id: int :param subscriber_id: The WAMP session ID of the subscriber to remove. :type subscriber_id: int """ subscriber = self._router._session_id_to_session.get(subscriber_id, None) if not subscriber: raise ApplicationError( ApplicationError.NO_SUCH_SESSION, message=u'no session with ID {} exists on this router'.format(subscriber_id), ) subscription = self._router._broker._subscription_map.get_observation_by_id(subscription_id) if subscription and not is_protected_uri(subscription.uri): if subscriber not in subscription.observers: raise ApplicationError( ApplicationError.NO_SUCH_SUBSCRIPTION, u'session {} is not subscribed on subscription {} on this broker'.format(subscriber_id, subscription_id), ) self._router._broker.removeSubscriber(subscription, subscriber, reason=reason) else: raise ApplicationError( ApplicationError.NO_SUCH_SUBSCRIPTION, u'no subscription with ID {} exists on this broker'.format(subscription_id), )
def registration_remove_callee(self, registration_id, callee_id, reason=None): """ Forcefully remove callee from registration. :param registration_id: The ID of the registration to remove the callee from. :type registration_id: int :param callee_id: The WAMP session ID of the callee to remove. :type callee_id: int """ callee = self._router._session_id_to_session.get(callee_id, None) if not callee: raise ApplicationError( ApplicationError.NO_SUCH_SESSION, u'no session with ID {} exists on this router'.format(callee_id), ) registration = self._router._dealer._registration_map.get_observation_by_id(registration_id) if registration and not is_protected_uri(registration.uri): if callee not in registration.observers: raise ApplicationError( ApplicationError.NO_SUCH_REGISTRATION, u'session {} is not registered on registration {} on this dealer'.format(callee_id, registration_id), ) self._router._dealer.removeCallee(registration, callee, reason=reason) else: raise ApplicationError( ApplicationError.NO_SUCH_REGISTRATION, u'no registration with ID {} exists on this dealer'.format(registration_id), )
def subscription_get(self, subscription_id, details=None): """ Get subscription details. :param subscription_id: The ID of the subscription to retrieve. :type subscription_id: int :returns: The subscription details. :rtype: dict """ subscription = self._router._broker._subscription_map.get_observation_by_id( subscription_id) if subscription and is_protected_uri(subscription.uri, details): subscription_details = { u'id': subscription.id, u'created': subscription.created, u'uri': subscription.uri, u'match': subscription.match, } return subscription_details else: raise ApplicationError( ApplicationError.NO_SUCH_SUBSCRIPTION, u'no subscription with ID {} exists on this broker'.format( subscription_id), )
def subscription_match(self, topic, details=None): """ Given a topic URI, returns all subscriptions matching the topic. This essentially models what a broker does for dispatching an incoming publication. :param topic: The topic to match. :type topic: str :returns: All matching subscriptions or ``None``. :rtype: obj or None """ subscriptions = self._router._broker._subscription_map.match_observations(topic) if subscriptions: subscription_ids = [] for subscription in subscriptions: if not is_protected_uri(subscription.uri, details): subscription_ids.append(subscription.id) if subscription_ids: return subscription_ids else: return None else: return None
def registration_get(self, registration_id): """ Get registration details. :param registration_id: The ID of the registration to retrieve. :type registration_id: int :returns: The registration details. :rtype: dict """ registration = self._router._dealer._registration_map.get_observation_by_id(registration_id) if registration and not is_protected_uri(registration.uri): registration_details = { 'id': registration.id, 'created': registration.created, 'uri': registration.uri, 'match': registration.match, 'invoke': registration.extra.invoke, } return registration_details else: raise ApplicationError( ApplicationError.NO_SUCH_REGISTRATION, "no registration with ID {} exists on this dealer".format(registration_id), )
def registration_list_callees(self, registration_id, details=None): """ Retrieve list of callees (WAMP session IDs) registered on (attached to) a registration. :param registration_id: The ID of the registration to get callees for. :type registration_id: int :returns: A list of WAMP session IDs of callees currently attached to the registration. :rtype: list """ registration = self._router._dealer._registration_map.get_observation_by_id(registration_id) if registration: if is_protected_uri(registration.uri, details): raise ApplicationError( ApplicationError.NOT_AUTHORIZED, message=u'not authorized to list callees for protected URI "{}"'.format(registration.uri), ) session_ids = [] for callee in registration.observers: session_ids.append(callee._session_id) return session_ids else: raise ApplicationError( ApplicationError.NO_SUCH_REGISTRATION, u'no registration with ID {} exists on this dealer'.format(registration_id), )
def subscription_count_subscribers(self, subscription_id, details=None): """ Retrieve number of subscribers subscribed on (attached to) a subscription. :param subscription_id: The ID of the subscription to get the number subscribers for. :type subscription_id: int :returns: Number of subscribers currently attached to the subscription. :rtype: int """ subscription = self._router._broker._subscription_map.get_observation_by_id(subscription_id) if subscription: if is_protected_uri(subscription.uri, details): raise ApplicationError( ApplicationError.NOT_AUTHORIZED, message=u'not authorized to count subscribers for protected URI "{}"'.format(subscription.uri), ) return len(subscription.observers) else: raise ApplicationError( ApplicationError.NO_SUCH_SUBSCRIPTION, u'no subscription with ID {} exists on this broker'.format(subscription_id), )
def subscription_get_events(self, subscription_id, limit=10): """ Return history of events for given subscription. :param subscription_id: The ID of the subscription to get events for. :type subscription_id: int :param limit: Return at most this many events. :type limit: int :returns: List of events. :rtype: list """ self.log.info("subscription_get_events({subscription_id}, {limit})", subscription_id=subscription_id, limit=limit) subscription = self._router._broker._subscription_map.get_observation_by_id(subscription_id) if subscription and not is_protected_uri(subscription.uri): events = self._router._broker._event_store.get_events(subscription_id, limit) if events is None: raise Exception("event history for the given subscription is unavailable") raise ApplicationError( u'wamp.error.history_unavailable', message="event history for the given subscription is unavailable", ) else: return events else: raise ApplicationError( ApplicationError.NO_SUCH_SUBSCRIPTION, "no subscription with ID {} exists on this broker".format(subscription_id), )
def subscription_get(self, subscription_id, details=None): """ Get subscription details. :param subscription_id: The ID of the subscription to retrieve. :type subscription_id: int :returns: The subscription details. :rtype: dict """ subscription = self._router._broker._subscription_map.get_observation_by_id(subscription_id) if subscription: if is_protected_uri(subscription.uri, details): raise ApplicationError( ApplicationError.NOT_AUTHORIZED, message=u'not authorized to get subscription for protected URI "{}"'.format(subscription.uri), ) subscription_details = { u'id': subscription.id, u'created': subscription.created, u'uri': subscription.uri, u'match': subscription.match, } return subscription_details else: raise ApplicationError( ApplicationError.NO_SUCH_SUBSCRIPTION, u'no subscription with ID {} exists on this broker'.format(subscription_id), )
def subscription_list_subscribers(self, subscription_id, details=None): """ Retrieve list of subscribers (WAMP session IDs) subscribed on (attached to) a subscription. :param subscription_id: The ID of the subscription to get subscribers for. :type subscription_id: int :returns: A list of WAMP session IDs of subscribers currently attached to the subscription. :rtype: list """ subscription = self._router._broker._subscription_map.get_observation_by_id(subscription_id) if subscription: if is_protected_uri(subscription.uri, details): raise ApplicationError( ApplicationError.NOT_AUTHORIZED, message=u'not authorized to list subscribers for protected URI "{}"'.format(subscription.uri), ) session_ids = [] for subscriber in subscription.observers: session_ids.append(subscriber._session_id) return session_ids else: raise ApplicationError( ApplicationError.NO_SUCH_SUBSCRIPTION, u'no subscription with ID {} exists on this broker'.format(subscription_id), )
def registration_get(self, registration_id): """ Get registration details. :param registration_id: The ID of the registration to retrieve. :type registration_id: int :returns: The registration details. :rtype: dict """ registration = self._router._dealer._registration_map.get_observation_by_id(registration_id) if registration and not is_protected_uri(registration.uri): registration_details = { u'id': registration.id, u'created': registration.created, u'uri': registration.uri, u'match': registration.match, u'invoke': registration.extra.invoke, } return registration_details else: raise ApplicationError( ApplicationError.NO_SUCH_REGISTRATION, u'no registration with ID {} exists on this dealer'.format(registration_id), )
def subscription_get_events(self, subscription_id, limit=10, details=None): """ Return history of events for given subscription. :param subscription_id: The ID of the subscription to get events for. :type subscription_id: int :param limit: Return at most this many events. :type limit: int :returns: List of events. :rtype: list """ self.log.debug('subscription_get_events({subscription_id}, {limit})', subscription_id=subscription_id, limit=limit) if not self._router._broker._event_store: raise ApplicationError( u'wamp.error.history_unavailable', message=u'event history not available or enabled', ) subscription = self._router._broker._subscription_map.get_observation_by_id( subscription_id) if subscription: if is_protected_uri(subscription.uri, details): raise ApplicationError( ApplicationError.NOT_AUTHORIZED, message= u'not authorized to retrieve event history for protected URI "{}"' .format(subscription.uri), ) events = self._router._broker._event_store.get_events( subscription_id, limit) if events is None: # a return value of None in above signals that event history really # is not available/enabled (which is different from an empty history!) raise ApplicationError( u'wamp.error.history_unavailable', message= u'event history for the given subscription is not available or enabled', ) else: return events else: raise ApplicationError( ApplicationError.NO_SUCH_SUBSCRIPTION, u'no subscription with ID {} exists on this broker'.format( subscription_id), )
def registration_count_callees(self, registration_id): """ Retrieve number of callees registered on (attached to) a registration. :param registration_id: The ID of the registration to get the number of callees for. :type registration_id: int :returns: Number of callees currently attached to the registration. :rtype: int """ registration = self._router._dealer._registration_map.get_observation_by_id(registration_id) if registration and not is_protected_uri(registration.uri): return len(registration.observers) else: raise ApplicationError(ApplicationError.NO_SUCH_REGISTRATION, message="no registration with ID {} exists on this dealer".format(registration_id))
def subscription_count_subscribers(self, subscription_id): """ Retrieve number of subscribers subscribed on (attached to) a subscription. :param subscription_id: The ID of the subscription to get the number subscribers for. :type subscription_id: int :returns: Number of subscribers currently attached to the subscription. :rtype: int """ subscription = self._router._broker._subscription_map.get_observation_by_id(subscription_id) if subscription and not is_protected_uri(subscription.uri): return len(subscription.observers) else: raise ApplicationError(ApplicationError.NO_SUCH_SUBSCRIPTION, message="no subscription with ID {} exists on this broker".format(subscription_id))
def registration_match(self, procedure): """ Given a procedure URI, return the registration best matching the procedure. This essentially models what a dealer does for dispatching an incoming call. :param procedure: The procedure to match. :type procedure: unicode :returns: The best matching registration or ``None``. :rtype: obj or None """ registration = self._router._dealer._registration_map.best_matching_observation(procedure) if registration and not is_protected_uri(registration.uri): return registration.id else: return None
def registration_list_callees(self, registration_id): """ Retrieve list of callees (WAMP session IDs) registered on (attached to) a registration. :param registration_id: The ID of the registration to get callees for. :type registration_id: int :returns: A list of WAMP session IDs of callees currently attached to the registration. :rtype: list """ registration = self._router._dealer._registration_map.get_observation_by_id(registration_id) if registration and not is_protected_uri(registration.uri): session_ids = [] for callee in registration.observers: session_ids.append(callee._session_id) return session_ids else: raise ApplicationError(ApplicationError.NO_SUCH_REGISTRATION, message="no registration with ID {} exists on this dealer".format(registration_id))
def subscription_list_subscribers(self, subscription_id): """ Retrieve list of subscribers (WAMP session IDs) subscribed on (attached to) a subscription. :param subscription_id: The ID of the subscription to get subscribers for. :type subscription_id: int :returns: A list of WAMP session IDs of subscribers currently attached to the subscription. :rtype: list """ subscription = self._router._broker._subscription_map.get_observation_by_id(subscription_id) if subscription and not is_protected_uri(subscription.uri): session_ids = [] for subscriber in subscription.observers: session_ids.append(subscriber._session_id) return session_ids else: raise ApplicationError(ApplicationError.NO_SUCH_SUBSCRIPTION, message="no subscription with ID {} exists on this broker".format(subscription_id))
def subscription_get_events(self, subscription_id, limit=10, details=None): """ Return history of events for given subscription. :param subscription_id: The ID of the subscription to get events for. :type subscription_id: int :param limit: Return at most this many events. :type limit: int :returns: List of events. :rtype: list """ self.log.debug('subscription_get_events({subscription_id}, {limit})', subscription_id=subscription_id, limit=limit) if not self._router._broker._event_store: raise ApplicationError( u'wamp.error.history_unavailable', message=u'event history not available or enabled', ) subscription = self._router._broker._subscription_map.get_observation_by_id(subscription_id) if subscription: if is_protected_uri(subscription.uri, details): raise ApplicationError( ApplicationError.NOT_AUTHORIZED, message=u'not authorized to retrieve event history for protected URI "{}"'.format(subscription.uri), ) events = self._router._broker._event_store.get_events(subscription_id, limit) if events is None: # a return value of None in above signals that event history really # is not available/enabled (which is different from an empty history!) raise ApplicationError( u'wamp.error.history_unavailable', message=u'event history for the given subscription is not available or enabled', ) else: return events else: raise ApplicationError( ApplicationError.NO_SUCH_SUBSCRIPTION, u'no subscription with ID {} exists on this broker'.format(subscription_id), )
def subscription_lookup(self, topic, options=None): """ Given a topic URI (and options), return the subscription (if any) managing the topic. This essentially models what a broker does when subscribing for a topic. :param topic: The topic to lookup the subscription for. :type topic: unicode :param options: Same options as when subscribing to a topic. :type options: dict or None :returns: The ID of the subscription managing the topic or ``None``. :rtype: int or None """ options = options or {} match = options.get('match', u'exact') subscription = self._router._broker._subscription_map.get_observation(topic, match) if subscription and not is_protected_uri(subscription.uri): return subscription.id else: return None
def registration_lookup(self, procedure, options=None): """ Given a procedure URI (and options), return the registration (if any) managing the procedure. This essentially models what a dealer does when registering for a procedure. :param procedure: The procedure to lookup the registration for. :type procedure: unicode :param options: Same options as when registering a procedure. :type options: dict or None :returns: The ID of the registration managing the procedure or ``None``. :rtype: int or None """ options = options or {} match = options.get('match', u'exact') registration = self._router._dealer._registration_map.get_observation(procedure, match) if registration and not is_protected_uri(registration.uri): return registration.id else: return None
def subscription_lookup(self, topic, options=None): """ Given a topic URI (and options), return the subscription (if any) managing the topic. This essentially models what a broker does when subscribing for a topic. :param topic: The topic to lookup the subscription for. :type topic: unicode :param options: Same options as when subscribing to a topic. :type options: dict or None :returns: The ID of the subscription managing the topic or ``None``. :rtype: int or None """ options = options or {} match = options.get(u'match', u'exact') subscription = self._router._broker._subscription_map.get_observation(topic, match) if subscription and not is_protected_uri(subscription.uri): return subscription.id else: return None
def registration_lookup(self, procedure, options=None): """ Given a procedure URI (and options), return the registration (if any) managing the procedure. This essentially models what a dealer does when registering for a procedure. :param procedure: The procedure to lookup the registration for. :type procedure: unicode :param options: Same options as when registering a procedure. :type options: dict or None :returns: The ID of the registration managing the procedure or ``None``. :rtype: int or None """ options = options or {} match = options.get(u'match', u'exact') registration = self._router._dealer._registration_map.get_observation(procedure, match) if registration and not is_protected_uri(registration.uri): return registration.id else: return None
def subscription_get(self, subscription_id): """ Get subscription details. :param subscription_id: The ID of the subscription to retrieve. :type subscription_id: int :returns: The subscription details. :rtype: dict """ subscription = self._router._broker._subscription_map.get_observation_by_id(subscription_id) if subscription and not is_protected_uri(subscription.uri): subscription_details = { 'id': subscription.id, 'created': subscription.created, 'uri': subscription.uri, 'match': subscription.match, } return subscription_details else: raise ApplicationError(ApplicationError.NO_SUCH_SUBSCRIPTION, message="no subscription with ID {} exists on this broker".format(subscription_id))
def registration_count_callees(self, registration_id, details=None): """ Retrieve number of callees registered on (attached to) a registration. :param registration_id: The ID of the registration to get the number of callees for. :type registration_id: int :returns: Number of callees currently attached to the registration. :rtype: int """ registration = self._router._dealer._registration_map.get_observation_by_id(registration_id) if registration: if is_protected_uri(registration.uri, details): raise ApplicationError( ApplicationError.NOT_AUTHORIZED, message=u'not authorized to count callees for protected URI "{}"'.format(registration.uri), ) return len(registration.observers) else: raise ApplicationError( ApplicationError.NO_SUCH_REGISTRATION, u'no registration with ID {} exists on this dealer'.format(registration_id), )
def subscription_list(self, session_id=None, details=None): """ List current subscriptions. :returns: A dictionary with three entries for the match policies 'exact', 'prefix' and 'wildcard', with a list of subscription IDs for each. :rtype: dict """ if session_id: s2s = self._router._broker._session_to_subscriptions session = None if session_id in self._router._session_id_to_session: session = self._router._session_id_to_session[session_id] if is_restricted_session(session): session = None if not session or session not in s2s: raise ApplicationError( ApplicationError.NO_SUCH_SESSION, u'no session with ID {} exists on this router'.format( session_id), ) _subs = s2s[session] subs = { u'exact': [sub.id for sub in _subs if sub.match == u'exact'], u'prefix': [sub.id for sub in _subs if sub.match == u'prefix'], u'wildcard': [sub.id for sub in _subs if sub.match == u'wildcard'], } return subs else: subscription_map = self._router._broker._subscription_map subscriptions_exact = [] for subscription in subscription_map._observations_exact.values(): if not is_protected_uri(subscription.uri, details): subscriptions_exact.append(subscription.id) subscriptions_prefix = [] for subscription in subscription_map._observations_prefix.values(): if not is_protected_uri(subscription.uri, details): subscriptions_prefix.append(subscription.id) subscriptions_wildcard = [] # FIXME # for subscription in subscription_map._observations_wildcard.values(): # if not is_protected_uri(subscription.uri, details): # subscriptions_wildcard.append(subscription.id) subs = { u'exact': subscriptions_exact, u'prefix': subscriptions_prefix, u'wildcard': subscriptions_wildcard, } return subs
def registration_list(self, session_id=None, details=None): """ List current registrations. :returns: A dictionary with three entries for the match policies 'exact', 'prefix' and 'wildcard', with a list of registration IDs for each. :rtype: dict """ if session_id: s2r = self._router._dealer._session_to_registrations session = None if session_id in self._router._session_id_to_session: session = self._router._session_id_to_session[session_id] if is_restricted_session(session): session = None if not session or session not in s2r: raise ApplicationError( ApplicationError.NO_SUCH_SESSION, u'no session with ID {} exists on this router'.format( session_id), ) _regs = s2r[session] regs = { u'exact': [reg.id for reg in _regs if reg.match == u'exact'], u'prefix': [reg.id for reg in _regs if reg.match == u'prefix'], u'wildcard': [reg.id for reg in _regs if reg.match == u'wildcard'], } return regs else: registration_map = self._router._dealer._registration_map registrations_exact = [] for registration in registration_map._observations_exact.values(): if not is_protected_uri(registration.uri, details): registrations_exact.append(registration.id) registrations_prefix = [] for registration in registration_map._observations_prefix.values(): if not is_protected_uri(registration.uri, details): registrations_prefix.append(registration.id) registrations_wildcard = [] for registration in registration_map._observations_wildcard.values( ): if not is_protected_uri(registration.uri, details): registrations_wildcard.append(registration.id) regs = { u'exact': registrations_exact, u'prefix': registrations_prefix, u'wildcard': registrations_wildcard, } return regs