Search in sources :

Example 6 with TaskExecutorImpl

use of org.apache.qpid.server.configuration.updater.TaskExecutorImpl in project qpid-broker-j by apache.

the class BrokerImplTest method setUp.

@Before
public void setUp() throws Exception {
    _taskExecutor = new TaskExecutorImpl();
    _taskExecutor.start();
    _preferenceStore = mock(PreferenceStore.class);
    _systemConfig = BrokerTestHelper.mockWithSystemPrincipal(SystemConfig.class, mock(Principal.class));
    when(_systemConfig.getTaskExecutor()).thenReturn(_taskExecutor);
    when(_systemConfig.getChildExecutor()).thenReturn(_taskExecutor);
    when(_systemConfig.getModel()).thenReturn(BrokerModel.getInstance());
    when(_systemConfig.getEventLogger()).thenReturn(new EventLogger());
    when(_systemConfig.getCategoryClass()).thenReturn(SystemConfig.class);
    when(_systemConfig.createPreferenceStore()).thenReturn(_preferenceStore);
}
Also used : TaskExecutorImpl(org.apache.qpid.server.configuration.updater.TaskExecutorImpl) SystemConfig(org.apache.qpid.server.model.SystemConfig) EventLogger(org.apache.qpid.server.logging.EventLogger) PreferenceStore(org.apache.qpid.server.store.preferences.PreferenceStore) Before(org.junit.Before)

Example 7 with TaskExecutorImpl

use of org.apache.qpid.server.configuration.updater.TaskExecutorImpl in project qpid-broker-j by apache.

the class ProtocolEngine_1_0_0Test method setUp.

@Before
public void setUp() throws Exception {
    _networkConnection = mock(ServerNetworkConnection.class);
    when(_networkConnection.getLocalAddress()).thenReturn(new InetSocketAddress(0));
    when(_networkConnection.getSelectedHost()).thenReturn("localhost");
    _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);
    doAnswer(new Answer() {

        @Override
        public Object answer(final InvocationOnMock invocation) throws Throwable {
            _connection = connectionCaptor.getValue();
            throw new SoleConnectionEnforcementPolicyException(null, Collections.emptySet(), "abc1");
        }
    }).when(_virtualHost).registerConnection(connectionCaptor.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) SoleConnectionEnforcementPolicyException(org.apache.qpid.server.protocol.v1_0.type.extensions.soleconn.SoleConnectionEnforcementPolicyException) 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) 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) Before(org.junit.Before)

Example 8 with TaskExecutorImpl

use of org.apache.qpid.server.configuration.updater.TaskExecutorImpl in project qpid-broker-j by apache.

the class BrokerImpl method performActivation.

private void performActivation() {
    final DescendantScope descendantScope = getContextValue(DescendantScope.class, BROKER_FAIL_STARTUP_WITH_ERRORED_CHILD_SCOPE);
    List<ConfiguredObject<?>> failedChildren = getChildrenInState(this, State.ERRORED, descendantScope);
    if (!failedChildren.isEmpty()) {
        for (ConfiguredObject<?> o : failedChildren) {
            LOGGER.warn("{} child object '{}' of type '{}' is {}", o.getParent().getCategoryClass().getSimpleName(), o.getName(), o.getClass().getSimpleName(), State.ERRORED);
        }
        getEventLogger().message(BrokerMessages.FAILED_CHILDREN(failedChildren.toString()));
    }
    _documentationUrl = getContextValue(String.class, QPID_DOCUMENTATION_URL);
    final boolean brokerShutdownOnErroredChild = getContextValue(Boolean.class, BROKER_FAIL_STARTUP_WITH_ERRORED_CHILD);
    if (!_parent.isManagementMode() && brokerShutdownOnErroredChild && !failedChildren.isEmpty()) {
        throw new IllegalStateException(String.format("Broker context variable %s is set and the broker has %s children", BROKER_FAIL_STARTUP_WITH_ERRORED_CHILD, State.ERRORED));
    }
    updateAccessControl();
    _houseKeepingTaskExecutor = new HousekeepingExecutor("broker-" + getName() + "-pool", getHousekeepingThreadCount(), getSystemTaskSubject("Housekeeping", _principal));
    initialiseStatisticsReporting();
    scheduleDirectMemoryCheck();
    _assignTargetSizeSchedulingFuture = scheduleHouseKeepingTask(getHousekeepingCheckPeriod(), TimeUnit.MILLISECONDS, this::assignTargetSizes);
    final PreferenceStoreUpdaterImpl updater = new PreferenceStoreUpdaterImpl();
    final Collection<PreferenceRecord> preferenceRecords = _preferenceStore.openAndLoad(updater);
    _preferenceTaskExecutor = new TaskExecutorImpl("broker-" + getName() + "-preferences", null);
    _preferenceTaskExecutor.start();
    PreferencesRecoverer preferencesRecoverer = new PreferencesRecoverer(_preferenceTaskExecutor);
    preferencesRecoverer.recoverPreferences(this, preferenceRecords, _preferenceStore);
    if (isManagementMode()) {
        _eventLogger.message(BrokerMessages.MANAGEMENT_MODE(SystemConfig.MANAGEMENT_MODE_USER_NAME, _parent.getManagementModePassword()));
    }
    setState(State.ACTIVE);
}
Also used : HousekeepingExecutor(org.apache.qpid.server.util.HousekeepingExecutor) TaskExecutorImpl(org.apache.qpid.server.configuration.updater.TaskExecutorImpl) PreferenceRecord(org.apache.qpid.server.store.preferences.PreferenceRecord) PreferenceStoreUpdaterImpl(org.apache.qpid.server.store.preferences.PreferenceStoreUpdaterImpl) PreferencesRecoverer(org.apache.qpid.server.store.preferences.PreferencesRecoverer)

Example 9 with TaskExecutorImpl

use of org.apache.qpid.server.configuration.updater.TaskExecutorImpl in project qpid-broker-j by apache.

the class AbstractVirtualHost method onActivate.

@StateTransition(currentState = { State.UNINITIALIZED, State.ERRORED }, desiredState = State.ACTIVE)
private ListenableFuture<Void> onActivate() {
    long threadPoolKeepAliveTimeout = getContextValue(Long.class, CONNECTION_THREAD_POOL_KEEP_ALIVE_TIMEOUT);
    final SuppressingInheritedAccessControlContextThreadFactory connectionThreadFactory = new SuppressingInheritedAccessControlContextThreadFactory("virtualhost-" + getName() + "-iopool", getSystemTaskSubject("IO Pool", getPrincipal()));
    _networkConnectionScheduler = new NetworkConnectionScheduler("virtualhost-" + getName() + "-iopool", getNumberOfSelectors(), getConnectionThreadPoolSize(), threadPoolKeepAliveTimeout, connectionThreadFactory);
    _networkConnectionScheduler.start();
    updateAccessControl();
    initialiseStatisticsReporting();
    MessageStore messageStore = getMessageStore();
    messageStore.openMessageStore(this);
    startFileSystemSpaceChecking();
    if (!(_virtualHostNode.getConfigurationStore() instanceof MessageStoreProvider)) {
        getEventLogger().message(getMessageStoreLogSubject(), MessageStoreMessages.CREATED());
        getEventLogger().message(getMessageStoreLogSubject(), MessageStoreMessages.STORE_LOCATION(messageStore.getStoreLocation()));
    }
    messageStore.upgradeStoreStructure();
    if (_linkRegistry != null) {
        _linkRegistry.open();
    }
    getBroker().assignTargetSizes();
    final PreferenceStoreUpdater updater = new PreferenceStoreUpdaterImpl();
    Collection<PreferenceRecord> records = _preferenceStore.openAndLoad(updater);
    _preferenceTaskExecutor = new TaskExecutorImpl("virtualhost-" + getName() + "-preferences", null);
    _preferenceTaskExecutor.start();
    PreferencesRecoverer preferencesRecoverer = new PreferencesRecoverer(_preferenceTaskExecutor);
    preferencesRecoverer.recoverPreferences(this, records, _preferenceStore);
    activateConnectionLimiter();
    if (_createDefaultExchanges) {
        return doAfter(createDefaultExchanges(), new Runnable() {

            @Override
            public void run() {
                _createDefaultExchanges = false;
                postCreateDefaultExchangeTasks();
            }
        });
    } else {
        postCreateDefaultExchangeTasks();
        return Futures.immediateFuture(null);
    }
}
Also used : MessageStore(org.apache.qpid.server.store.MessageStore) PreferenceStoreUpdater(org.apache.qpid.server.store.preferences.PreferenceStoreUpdater) TaskExecutorImpl(org.apache.qpid.server.configuration.updater.TaskExecutorImpl) PreferenceRecord(org.apache.qpid.server.store.preferences.PreferenceRecord) SuppressingInheritedAccessControlContextThreadFactory(org.apache.qpid.server.pool.SuppressingInheritedAccessControlContextThreadFactory) MessageStoreProvider(org.apache.qpid.server.store.MessageStoreProvider) PreferenceStoreUpdaterImpl(org.apache.qpid.server.store.preferences.PreferenceStoreUpdaterImpl) PreferencesRecoverer(org.apache.qpid.server.store.preferences.PreferencesRecoverer) NetworkConnectionScheduler(org.apache.qpid.server.transport.NetworkConnectionScheduler) StateTransition(org.apache.qpid.server.model.StateTransition)

Example 10 with TaskExecutorImpl

use of org.apache.qpid.server.configuration.updater.TaskExecutorImpl in project qpid-broker-j by apache.

the class ServerSessionTest method createMockPort.

public AmqpPort createMockPort() {
    AmqpPort port = mock(AmqpPort.class);
    TaskExecutor childExecutor = new TaskExecutorImpl();
    childExecutor.start();
    when(port.getChildExecutor()).thenReturn(childExecutor);
    when(port.getCategoryClass()).thenReturn(Port.class);
    when(port.getModel()).thenReturn(BrokerModel.getInstance());
    return port;
}
Also used : CurrentThreadTaskExecutor(org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor) TaskExecutor(org.apache.qpid.server.configuration.updater.TaskExecutor) TaskExecutorImpl(org.apache.qpid.server.configuration.updater.TaskExecutorImpl) AmqpPort(org.apache.qpid.server.model.port.AmqpPort)

Aggregations

TaskExecutorImpl (org.apache.qpid.server.configuration.updater.TaskExecutorImpl)15 Before (org.junit.Before)12 EventLogger (org.apache.qpid.server.logging.EventLogger)7 Broker (org.apache.qpid.server.model.Broker)7 BrokerModel (org.apache.qpid.server.model.BrokerModel)6 Model (org.apache.qpid.server.model.Model)6 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)5 HashMap (java.util.HashMap)4 Principal (java.security.Principal)3 TaskExecutor (org.apache.qpid.server.configuration.updater.TaskExecutor)3 SystemConfig (org.apache.qpid.server.model.SystemConfig)3 VirtualHostNode (org.apache.qpid.server.model.VirtualHostNode)3 AmqpPort (org.apache.qpid.server.model.port.AmqpPort)3 PreferenceStore (org.apache.qpid.server.store.preferences.PreferenceStore)3 File (java.io.File)2 InetSocketAddress (java.net.InetSocketAddress)2 Subject (javax.security.auth.Subject)2 AuthenticationProvider (org.apache.qpid.server.model.AuthenticationProvider)2 ConfiguredObjectFactory (org.apache.qpid.server.model.ConfiguredObjectFactory)2 VirtualHost (org.apache.qpid.server.model.VirtualHost)2