private void switchToSessionExclusivity() throws ExistingConsumerPreventsExclusive { switch(_exclusive) { case NONE: case PRINCIPAL: case CONTAINER: case CONNECTION: AMQPSession<?,?> session = null; Iterator<QueueConsumer<?,?>> queueConsumerIterator = _queueConsumerManager.getAllIterator(); while(queueConsumerIterator.hasNext()) { QueueConsumer<?,?> c = queueConsumerIterator.next(); if(session == null) { session = c.getSession(); } else if(!session.equals(c.getSession())) { throw new ExistingConsumerPreventsExclusive(); } } _exclusiveOwner = session; break; case LINK: _exclusiveOwner = _exclusiveSubscriber == null ? null : _exclusiveSubscriber.getSession().getAMQPConnection(); } }
@Override public boolean matches(Filterable message) { final Collection<QueueConsumer<?,?>> consumers = _queue.getConsumers(); for(QueueConsumer<?,?> c : consumers) { if(c.getSession().getConnectionReference() == message.getConnectionReference()) { return false; } } return !consumers.isEmpty(); }
private void switchToConnectionExclusivity() throws ExistingConsumerPreventsExclusive { switch(_exclusive) { case NONE: case CONTAINER: case PRINCIPAL: AMQPConnection con = null; Iterator<QueueConsumer<?,?>> queueConsumerIterator = _queueConsumerManager.getAllIterator(); while(queueConsumerIterator.hasNext()) { QueueConsumer<?,?> c = queueConsumerIterator.next(); if(con == null) { con = c.getSession().getAMQPConnection(); } else if(!con.equals(c.getSession().getAMQPConnection())) { throw new ExistingConsumerPreventsExclusive(); } } _exclusiveOwner = con; break; case SESSION: _exclusiveOwner = _exclusiveOwner == null ? null : ((AMQPSession<?,?>)_exclusiveOwner).getAMQPConnection(); break; case LINK: _exclusiveOwner = _exclusiveSubscriber == null ? null : _exclusiveSubscriber.getSession().getAMQPConnection(); } }
if(principal == null) principal = c.getSession().getAMQPConnection().getAuthorizedPrincipal(); c.getSession().getAMQPConnection().getAuthorizedPrincipal().getName())) break; case LINK: _exclusiveOwner = _exclusiveSubscriber == null ? null : _exclusiveSubscriber.getSession().getAMQPConnection().getAuthorizedPrincipal();
@Override public boolean verifySessionAccess(final AMQPSession<?,?> session) { boolean allowed; switch(_exclusive) { case NONE: allowed = true; break; case SESSION: allowed = _exclusiveOwner == null || _exclusiveOwner == session; break; case CONNECTION: allowed = _exclusiveOwner == null || _exclusiveOwner == session.getAMQPConnection(); break; case PRINCIPAL: allowed = _exclusiveOwner == null || Objects.equals(((Principal) _exclusiveOwner).getName(), session.getAMQPConnection().getAuthorizedPrincipal().getName()); break; case CONTAINER: allowed = _exclusiveOwner == null || _exclusiveOwner.equals(session.getAMQPConnection().getRemoteContainerName()); break; case LINK: allowed = _exclusiveSubscriber == null || _exclusiveSubscriber.getSession() == session; break; default: throw new ServerScopedRuntimeException("Unknown exclusivity policy " + _exclusive); } return allowed; }
if(containerID == null) containerID = c.getSession().getAMQPConnection().getRemoteContainerName(); else if(!containerID.equals(c.getSession().getAMQPConnection().getRemoteContainerName())) break; case LINK: _exclusiveOwner = _exclusiveSubscriber == null ? null : _exclusiveSubscriber.getSession().getAMQPConnection().getRemoteContainerName();