Search in sources :

Example 6 with EventLogger

use of org.apache.qpid.server.logging.EventLogger in project qpid-broker-j by apache.

the class AbstractTestLogSubject method performLog.

protected List<Object> performLog(boolean statusUpdatesEnabled) {
    if (_subject == null) {
        throw new NullPointerException("LogSubject has not been set");
    }
    UnitTestMessageLogger logger = new UnitTestMessageLogger(statusUpdatesEnabled);
    EventLogger eventLogger = new EventLogger(logger);
    eventLogger.message(_subject, new LogMessage() {

        @Override
        public String toString() {
            return "<Log Message>";
        }

        @Override
        public String getLogHierarchy() {
            return "test.hierarchy";
        }
    });
    return logger.getLogMessages();
}
Also used : EventLogger(org.apache.qpid.server.logging.EventLogger) LogMessage(org.apache.qpid.server.logging.LogMessage) UnitTestMessageLogger(org.apache.qpid.server.logging.UnitTestMessageLogger)

Example 7 with EventLogger

use of org.apache.qpid.server.logging.EventLogger in project qpid-broker-j by apache.

the class BrokerTestHelper method createBrokerMock.

private static Broker<?> createBrokerMock(AccessControl accessControl) {
    ConfiguredObjectFactory objectFactory = new ConfiguredObjectFactoryImpl(BrokerModel.getInstance());
    EventLogger eventLogger = new EventLogger();
    SystemConfig systemConfig = mock(SystemConfig.class);
    when(systemConfig.getEventLogger()).thenReturn(eventLogger);
    when(systemConfig.getObjectFactory()).thenReturn(objectFactory);
    when(systemConfig.getModel()).thenReturn(objectFactory.getModel());
    when(systemConfig.getCategoryClass()).thenReturn(SystemConfig.class);
    when(systemConfig.getTypeClass()).thenReturn(SystemConfig.class);
    Broker broker = mockWithSystemPrincipalAndAccessControl(Broker.class, SYSTEM_PRINCIPAL, accessControl);
    when(broker.getId()).thenReturn(UUID.randomUUID());
    when(broker.getObjectFactory()).thenReturn(objectFactory);
    when(broker.getModel()).thenReturn(objectFactory.getModel());
    when(broker.getModelVersion()).thenReturn(BrokerModel.MODEL_VERSION);
    when(broker.getEventLogger()).thenReturn(eventLogger);
    when(broker.getCategoryClass()).thenReturn(Broker.class);
    when(broker.getTypeClass()).thenReturn(Broker.class);
    when(broker.getParent()).thenReturn(systemConfig);
    when(broker.getContextValue(eq(Long.class), eq(Broker.CHANNEL_FLOW_CONTROL_ENFORCEMENT_TIMEOUT))).thenReturn(0l);
    when(broker.getFlowToDiskThreshold()).thenReturn(Long.MAX_VALUE);
    when(broker.getTaskExecutor()).thenReturn(TASK_EXECUTOR);
    when(systemConfig.getTaskExecutor()).thenReturn(TASK_EXECUTOR);
    when(broker.getChildExecutor()).thenReturn(TASK_EXECUTOR);
    when(systemConfig.getChildExecutor()).thenReturn(TASK_EXECUTOR);
    when(systemConfig.createPreferenceStore()).thenReturn(mock(PreferenceStore.class));
    when(systemConfig.getChildren(Broker.class)).thenReturn(Collections.singleton(broker));
    return broker;
}
Also used : EventLogger(org.apache.qpid.server.logging.EventLogger) PreferenceStore(org.apache.qpid.server.store.preferences.PreferenceStore)

Example 8 with EventLogger

use of org.apache.qpid.server.logging.EventLogger in project qpid-broker-j by apache.

the class BrokerImplTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    _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)

Example 9 with EventLogger

use of org.apache.qpid.server.logging.EventLogger in project qpid-broker-j by apache.

the class AmqpPortImplTest method testConnectionCounting.

public void testConnectionCounting() {
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(AmqpPort.PORT, 0);
    attributes.put(AmqpPort.NAME, getTestName());
    attributes.put(AmqpPort.AUTHENTICATION_PROVIDER, AUTHENTICATION_PROVIDER_NAME);
    attributes.put(AmqpPort.MAX_OPEN_CONNECTIONS, 10);
    attributes.put(AmqpPort.CONTEXT, Collections.singletonMap(AmqpPort.OPEN_CONNECTIONS_WARN_PERCENT, "80"));
    _port = new AmqpPortImpl(attributes, _broker);
    _port.create();
    EventLogger mockLogger = mock(EventLogger.class);
    when(_broker.getEventLogger()).thenReturn(mockLogger);
    for (int i = 0; i < 8; i++) {
        assertTrue(_port.canAcceptNewConnection(new InetSocketAddress("example.org", 0)));
        _port.incrementConnectionCount();
        assertEquals(i + 1, _port.getConnectionCount());
        verify(mockLogger, never()).message(any(LogSubject.class), any(LogMessage.class));
    }
    assertTrue(_port.canAcceptNewConnection(new InetSocketAddress("example.org", 0)));
    _port.incrementConnectionCount();
    assertEquals(9, _port.getConnectionCount());
    verify(mockLogger, times(1)).message(any(LogSubject.class), any(LogMessage.class));
    assertTrue(_port.canAcceptNewConnection(new InetSocketAddress("example.org", 0)));
    _port.incrementConnectionCount();
    assertEquals(10, _port.getConnectionCount());
    verify(mockLogger, times(1)).message(any(LogSubject.class), any(LogMessage.class));
    assertFalse(_port.canAcceptNewConnection(new InetSocketAddress("example.org", 0)));
}
Also used : HashMap(java.util.HashMap) EventLogger(org.apache.qpid.server.logging.EventLogger) LogMessage(org.apache.qpid.server.logging.LogMessage) InetSocketAddress(java.net.InetSocketAddress) LogSubject(org.apache.qpid.server.logging.LogSubject)

Example 10 with EventLogger

use of org.apache.qpid.server.logging.EventLogger in project qpid-broker-j by apache.

the class SynchronousMessageStoreRecoverer method recover.

@Override
public ListenableFuture<Void> recover(QueueManagingVirtualHost<?> virtualHost) {
    EventLogger eventLogger = virtualHost.getEventLogger();
    MessageStore store = virtualHost.getMessageStore();
    MessageStore.MessageStoreReader storeReader = store.newMessageStoreReader();
    MessageStoreLogSubject logSubject = new MessageStoreLogSubject(virtualHost.getName(), store.getClass().getSimpleName());
    Map<Queue<?>, Integer> queueRecoveries = new TreeMap<>();
    Map<Long, ServerMessage<?>> recoveredMessages = new HashMap<>();
    Map<Long, StoredMessage<?>> unusedMessages = new TreeMap<>();
    Map<UUID, Integer> unknownQueuesWithMessages = new HashMap<>();
    Map<Queue<?>, Integer> queuesWithUnknownMessages = new HashMap<>();
    eventLogger.message(logSubject, MessageStoreMessages.RECOVERY_START());
    storeReader.visitMessages(new MessageVisitor(recoveredMessages, unusedMessages));
    eventLogger.message(logSubject, TransactionLogMessages.RECOVERY_START(null, false));
    try {
        storeReader.visitMessageInstances(new MessageInstanceVisitor(virtualHost, store, queueRecoveries, recoveredMessages, unusedMessages, unknownQueuesWithMessages, queuesWithUnknownMessages));
    } finally {
        if (!unknownQueuesWithMessages.isEmpty()) {
            unknownQueuesWithMessages.forEach((queueId, count) -> {
                LOGGER.info("Discarded {} entry(s) associated with queue id '{}' as a queue with this " + "id does not appear in the configuration.", count, queueId);
            });
        }
        if (!queuesWithUnknownMessages.isEmpty()) {
            queuesWithUnknownMessages.forEach((queue, count) -> {
                LOGGER.info("Discarded {} entry(s) associated with queue '{}' as the referenced message " + "does not exist.", count, queue.getName());
            });
        }
    }
    for (Map.Entry<Queue<?>, Integer> entry : queueRecoveries.entrySet()) {
        Queue<?> queue = entry.getKey();
        Integer deliveredCount = entry.getValue();
        eventLogger.message(logSubject, TransactionLogMessages.RECOVERED(deliveredCount, queue.getName()));
        eventLogger.message(logSubject, TransactionLogMessages.RECOVERY_COMPLETE(queue.getName(), true));
        queue.completeRecovery();
    }
    for (Queue<?> q : virtualHost.getChildren(Queue.class)) {
        if (!queueRecoveries.containsKey(q)) {
            q.completeRecovery();
        }
    }
    storeReader.visitDistributedTransactions(new DistributedTransactionVisitor(virtualHost, eventLogger, logSubject, recoveredMessages, unusedMessages));
    for (StoredMessage<?> m : unusedMessages.values()) {
        LOGGER.debug("Message id '{}' is orphaned, removing", m.getMessageNumber());
        m.remove();
    }
    if (unusedMessages.size() > 0) {
        LOGGER.info("Discarded {} orphaned message(s).", unusedMessages.size());
    }
    eventLogger.message(logSubject, TransactionLogMessages.RECOVERY_COMPLETE(null, false));
    eventLogger.message(logSubject, MessageStoreMessages.RECOVERED(recoveredMessages.size() - unusedMessages.size()));
    eventLogger.message(logSubject, MessageStoreMessages.RECOVERY_COMPLETE());
    return Futures.immediateFuture(null);
}
Also used : MessageStore(org.apache.qpid.server.store.MessageStore) EventLogger(org.apache.qpid.server.logging.EventLogger) HashMap(java.util.HashMap) ServerMessage(org.apache.qpid.server.message.ServerMessage) TreeMap(java.util.TreeMap) StoredMessage(org.apache.qpid.server.store.StoredMessage) MessageStoreLogSubject(org.apache.qpid.server.logging.subjects.MessageStoreLogSubject) UUID(java.util.UUID) Queue(org.apache.qpid.server.model.Queue) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Aggregations

EventLogger (org.apache.qpid.server.logging.EventLogger)40 Broker (org.apache.qpid.server.model.Broker)15 SystemConfig (org.apache.qpid.server.model.SystemConfig)10 TaskExecutor (org.apache.qpid.server.configuration.updater.TaskExecutor)8 HashMap (java.util.HashMap)7 CurrentThreadTaskExecutor (org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor)7 Principal (java.security.Principal)6 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)6 ConfiguredObjectFactoryImpl (org.apache.qpid.server.model.ConfiguredObjectFactoryImpl)6 TaskExecutorImpl (org.apache.qpid.server.configuration.updater.TaskExecutorImpl)5 InetSocketAddress (java.net.InetSocketAddress)4 BrokerModel (org.apache.qpid.server.model.BrokerModel)4 Model (org.apache.qpid.server.model.Model)4 VirtualHostNode (org.apache.qpid.server.model.VirtualHostNode)4 AuthenticatedPrincipal (org.apache.qpid.server.security.auth.AuthenticatedPrincipal)4 IOException (java.io.IOException)3 Map (java.util.Map)3 Subject (javax.security.auth.Subject)3 UnitTestMessageLogger (org.apache.qpid.server.logging.UnitTestMessageLogger)3 AmqpPort (org.apache.qpid.server.model.port.AmqpPort)3