Search in sources :

Example 1 with AMQPDescribedTypeRegistry

use of org.apache.qpid.server.protocol.v1_0.type.codec.AMQPDescribedTypeRegistry in project qpid-broker-j by apache.

the class ProtocolEngine_1_0_0Test method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    _networkConnection = mock(ServerNetworkConnection.class);
    when(_networkConnection.getLocalAddress()).thenReturn(new InetSocketAddress(0));
    _broker = mock(Broker.class);
    when(_broker.getModel()).thenReturn(BrokerModel.getInstance());
    when(_broker.getNetworkBufferSize()).thenReturn(256 * 1026);
    final TaskExecutor taskExecutor = new TaskExecutorImpl();
    taskExecutor.start();
    when(_broker.getChildExecutor()).thenReturn(taskExecutor);
    when(_broker.getTaskExecutor()).thenReturn(taskExecutor);
    when(_broker.getId()).thenReturn(UUID.randomUUID());
    when(_broker.getEventLogger()).thenReturn(new EventLogger());
    when(((Broker) _broker).getCategoryClass()).thenReturn(Broker.class);
    _port = mock(AmqpPort.class);
    when(_port.getChildExecutor()).thenReturn(taskExecutor);
    when(_port.getCategoryClass()).thenReturn(Port.class);
    when(_port.getModel()).thenReturn(BrokerModel.getInstance());
    final SubjectCreator subjectCreator = mock(SubjectCreator.class);
    _authenticationProvider = mock(AuthenticationProvider.class);
    when(_port.getAuthenticationProvider()).thenReturn(_authenticationProvider);
    _virtualHost = mock(VirtualHost.class);
    when(_virtualHost.getChildExecutor()).thenReturn(taskExecutor);
    when(_virtualHost.getModel()).thenReturn(BrokerModel.getInstance());
    when(_virtualHost.getState()).thenReturn(State.ACTIVE);
    when(_virtualHost.isActive()).thenReturn(true);
    final ArgumentCaptor<AMQPConnection> connectionCaptor = ArgumentCaptor.forClass(AMQPConnection.class);
    final ArgumentCaptor<ConnectionEstablishmentPolicy> establishmentPolicyCaptor = ArgumentCaptor.forClass(ConnectionEstablishmentPolicy.class);
    doAnswer(new Answer() {

        @Override
        public Object answer(final InvocationOnMock invocation) throws Throwable {
            _connection = connectionCaptor.getValue();
            return null;
        }
    }).when(_virtualHost).registerConnection(connectionCaptor.capture(), establishmentPolicyCaptor.capture());
    when(_virtualHost.getPrincipal()).thenReturn(mock(VirtualHostPrincipal.class));
    when(_port.getAddressSpace(anyString())).thenReturn(_virtualHost);
    when(_port.getSubjectCreator(anyBoolean(), anyString())).thenReturn(subjectCreator);
    final ArgumentCaptor<Principal> userCaptor = ArgumentCaptor.forClass(Principal.class);
    when(subjectCreator.createSubjectWithGroups(userCaptor.capture())).then(new Answer<Subject>() {

        @Override
        public Subject answer(final InvocationOnMock invocation) throws Throwable {
            Subject subject = new Subject();
            subject.getPrincipals().add(userCaptor.getValue());
            return subject;
        }
    });
    final ByteBufferSender sender = mock(ByteBufferSender.class);
    when(_networkConnection.getSender()).thenReturn(sender);
    AMQPDescribedTypeRegistry registry = AMQPDescribedTypeRegistry.newInstance().registerTransportLayer().registerMessagingLayer().registerTransactionLayer().registerSecurityLayer();
    _frameWriter = new FrameWriter(registry, new ByteBufferSender() {

        @Override
        public boolean isDirectBufferPreferred() {
            return false;
        }

        @Override
        public void send(final QpidByteBuffer msg) {
            _protocolEngine_1_0_0.received(msg);
        }

        @Override
        public void flush() {
        }

        @Override
        public void close() {
        }
    });
}
Also used : ByteBufferSender(org.apache.qpid.server.transport.ByteBufferSender) InetSocketAddress(java.net.InetSocketAddress) VirtualHostPrincipal(org.apache.qpid.server.virtualhost.VirtualHostPrincipal) AmqpPort(org.apache.qpid.server.model.port.AmqpPort) ServerNetworkConnection(org.apache.qpid.server.transport.ServerNetworkConnection) TaskExecutorImpl(org.apache.qpid.server.configuration.updater.TaskExecutorImpl) AMQPDescribedTypeRegistry(org.apache.qpid.server.protocol.v1_0.type.codec.AMQPDescribedTypeRegistry) Broker(org.apache.qpid.server.model.Broker) EventLogger(org.apache.qpid.server.logging.EventLogger) AuthenticationProvider(org.apache.qpid.server.model.AuthenticationProvider) Subject(javax.security.auth.Subject) FrameWriter(org.apache.qpid.server.protocol.v1_0.codec.FrameWriter) ConnectionEstablishmentPolicy(org.apache.qpid.server.virtualhost.ConnectionEstablishmentPolicy) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) TaskExecutor(org.apache.qpid.server.configuration.updater.TaskExecutor) AMQPConnection(org.apache.qpid.server.transport.AMQPConnection) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) VirtualHost(org.apache.qpid.server.model.VirtualHost) SubjectCreator(org.apache.qpid.server.security.SubjectCreator) VirtualHostPrincipal(org.apache.qpid.server.virtualhost.VirtualHostPrincipal) Principal(java.security.Principal) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal)

Example 2 with AMQPDescribedTypeRegistry

use of org.apache.qpid.server.protocol.v1_0.type.codec.AMQPDescribedTypeRegistry in project qpid-broker-j by apache.

the class AbstractLinkEndpoint method handleOversizedUnsettledMapIfNecessary.

private Attach handleOversizedUnsettledMapIfNecessary(final Attach attachToSend) {
    final AMQPDescribedTypeRegistry describedTypeRegistry = getSession().getConnection().getDescribedTypeRegistry();
    final ValueWriter<Attach> valueWriter = describedTypeRegistry.getValueWriter(attachToSend);
    if (valueWriter.getEncodedSize() + 8 > getSession().getConnection().getMaxFrameSize()) {
        _localIncompleteUnsettled = true;
        attachToSend.setIncompleteUnsettled(true);
        final int targetSize = getSession().getConnection().getMaxFrameSize();
        int lowIndex = 0;
        Map<Binary, DeliveryState> localUnsettledMap = attachToSend.getUnsettled();
        if (localUnsettledMap == null) {
            localUnsettledMap = Collections.emptyMap();
        }
        int highIndex = localUnsettledMap.size();
        int currentIndex = (highIndex - lowIndex) / 2;
        int oldIndex;
        HashMap<Binary, DeliveryState> unsettledMap = null;
        int totalSize;
        do {
            HashMap<Binary, DeliveryState> partialUnsettledMap = new HashMap<>(currentIndex);
            final Iterator<Map.Entry<Binary, DeliveryState>> iterator = localUnsettledMap.entrySet().iterator();
            for (int i = 0; i < currentIndex; ++i) {
                final Map.Entry<Binary, DeliveryState> entry = iterator.next();
                partialUnsettledMap.put(entry.getKey(), entry.getValue());
            }
            attachToSend.setUnsettled(partialUnsettledMap);
            totalSize = describedTypeRegistry.getValueWriter(attachToSend).getEncodedSize() + FRAME_HEADER_SIZE;
            if (totalSize > targetSize) {
                highIndex = currentIndex;
            } else if (totalSize < targetSize) {
                lowIndex = currentIndex;
                unsettledMap = partialUnsettledMap;
            } else {
                lowIndex = highIndex = currentIndex;
                unsettledMap = partialUnsettledMap;
            }
            oldIndex = currentIndex;
            currentIndex = lowIndex + (highIndex - lowIndex) / 2;
        } while (oldIndex != currentIndex);
        if (unsettledMap == null || unsettledMap.isEmpty()) {
            final End endWithError = new End();
            endWithError.setError(new Error(AmqpError.FRAME_SIZE_TOO_SMALL, "Cannot fit a single unsettled delivery into Attach frame."));
            getSession().end(endWithError);
        }
        attachToSend.setUnsettled(unsettledMap);
    } else {
        _localIncompleteUnsettled = false;
    }
    return attachToSend;
}
Also used : AMQPDescribedTypeRegistry(org.apache.qpid.server.protocol.v1_0.type.codec.AMQPDescribedTypeRegistry) HashMap(java.util.HashMap) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) DeliveryState(org.apache.qpid.server.protocol.v1_0.type.DeliveryState) End(org.apache.qpid.server.protocol.v1_0.type.transport.End) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

AMQPDescribedTypeRegistry (org.apache.qpid.server.protocol.v1_0.type.codec.AMQPDescribedTypeRegistry)2 InetSocketAddress (java.net.InetSocketAddress)1 Principal (java.security.Principal)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Subject (javax.security.auth.Subject)1 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)1 TaskExecutor (org.apache.qpid.server.configuration.updater.TaskExecutor)1 TaskExecutorImpl (org.apache.qpid.server.configuration.updater.TaskExecutorImpl)1 EventLogger (org.apache.qpid.server.logging.EventLogger)1 AuthenticationProvider (org.apache.qpid.server.model.AuthenticationProvider)1 Broker (org.apache.qpid.server.model.Broker)1 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)1 VirtualHost (org.apache.qpid.server.model.VirtualHost)1 AmqpPort (org.apache.qpid.server.model.port.AmqpPort)1 FrameWriter (org.apache.qpid.server.protocol.v1_0.codec.FrameWriter)1 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)1 DeliveryState (org.apache.qpid.server.protocol.v1_0.type.DeliveryState)1 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)1 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)1