Search in sources :

Example 1 with ILogger

use of com.hazelcast.logging.ILogger in project hazelcast by hazelcast.

the class ClientReplicatedMapProxy method addNearCacheInvalidateListener.

private void addNearCacheInvalidateListener() {
    try {
        EventHandler handler = new ReplicatedMapAddNearCacheEventHandler();
        invalidationListenerId = registerListener(createNearCacheInvalidationListenerCodec(), handler);
    } catch (Exception e) {
        ILogger logger = getContext().getLoggingService().getLogger(ClientReplicatedMapProxy.class);
        logger.severe("-----------------\nNear Cache is not initialized!\n-----------------", e);
    }
}
Also used : EventHandler(com.hazelcast.client.spi.EventHandler) ILogger(com.hazelcast.logging.ILogger)

Example 2 with ILogger

use of com.hazelcast.logging.ILogger in project hazelcast by hazelcast.

the class XAResourceProxy method end.

@Override
public void end(Xid xid, int flags) throws XAException {
    long threadId = currentThreadId();
    TransactionContext threadContext = threadContextMap.remove(threadId);
    ILogger logger = getContext().getLoggingService().getLogger(this.getClass());
    if (threadContext == null && logger.isFinestEnabled()) {
        logger.finest("There is no TransactionContext for the current thread: " + threadId);
    }
    List<TransactionContext> contexts = xidContextMap.get(xid);
    if (contexts == null && logger.isFinestEnabled()) {
        logger.finest("There is no TransactionContexts for the given xid: " + xid);
    }
}
Also used : TransactionContext(com.hazelcast.transaction.TransactionContext) ILogger(com.hazelcast.logging.ILogger)

Example 3 with ILogger

use of com.hazelcast.logging.ILogger in project hazelcast by hazelcast.

the class ClientClusterStateTest method testClusterShutdownDuringMapPutAll.

@Test
public void testClusterShutdownDuringMapPutAll() {
    warmUpPartitions(instances);
    waitAllForSafeState(instances);
    HazelcastInstance client = factory.newHazelcastClient();
    final IMap<Object, Object> map = client.getMap(randomMapName());
    final HashMap values = new HashMap<Double, Double>();
    for (int i = 0; i < 1000; i++) {
        double value = Math.random();
        values.put(value, value);
    }
    final int numThreads = 10;
    final CountDownLatch threadsFinished = new CountDownLatch(numThreads);
    final CountDownLatch threadsStarted = new CountDownLatch(numThreads);
    ExecutorService executor = Executors.newCachedThreadPool();
    for (int i = 0; i < numThreads; i++) {
        executor.execute(new Runnable() {

            @Override
            public void run() {
                ILogger logger = Logger.getLogger(getClass());
                threadsStarted.countDown();
                logger.info("putAll thread started");
                while (true) {
                    try {
                        map.putAll(values);
                        Thread.sleep(100);
                    } catch (IllegalStateException e) {
                        logger.warning("Expected exception for Map putAll during cluster shutdown:", e);
                        break;
                    } catch (TargetDisconnectedException e) {
                        logger.warning("Expected exception for Map putAll during cluster shutdown:", e);
                        break;
                    } catch (InterruptedException e) {
                    // do nothing
                    }
                }
                threadsFinished.countDown();
                logger.info("putAll thread finishing. Current finished thread count is:" + (numThreads - threadsFinished.getCount()));
            }
        });
    }
    try {
        assertTrue("All threads could not be started", threadsStarted.await(1, TimeUnit.MINUTES));
    } catch (InterruptedException e) {
        fail("All threads could not be started due to InterruptedException. Could not start " + threadsStarted.getCount() + " threads out of " + numThreads);
    }
    instance.getCluster().shutdown();
    executor.shutdown();
    try {
        assertTrue("All threads could not be finished", threadsFinished.await(2, TimeUnit.MINUTES));
    } catch (InterruptedException e) {
        fail("All threads could not be finished due to InterruptedException. Could not finish " + threadsFinished.getCount() + " threads out of " + numThreads);
    } finally {
        executor.shutdownNow();
    }
}
Also used : HashMap(java.util.HashMap) TargetDisconnectedException(com.hazelcast.spi.exception.TargetDisconnectedException) CountDownLatch(java.util.concurrent.CountDownLatch) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ExecutorService(java.util.concurrent.ExecutorService) ILogger(com.hazelcast.logging.ILogger) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with ILogger

use of com.hazelcast.logging.ILogger in project hazelcast by hazelcast.

the class ClientLoggerConfigurationTest method testLoggingWithConfiguration.

// Test with programmatic or system property configuration according to boolean parameter.
// the idea of the test is to configure a specific logging type for a client and then
// test its LoggingService produce instances of the expected Logger impl
protected void testLoggingWithConfiguration(boolean programmaticConfiguration) throws IOException {
    hazelcastFactory = new TestHazelcastFactory();
    Config cg = new Config();
    cg.setProperty("hazelcast.logging.type", "jdk");
    hazelcastFactory.newHazelcastInstance(cg);
    ClientConfig config = new ClientConfig();
    if (programmaticConfiguration) {
        config.setProperty("hazelcast.logging.type", "log4j2");
    } else {
        System.setProperty("hazelcast.logging.type", "log4j2");
    }
    client = hazelcastFactory.newHazelcastClient(config);
    ILogger clientLogger = client.getLoggingService().getLogger("loggerName");
    // this part is fragile.
    // client wraps the actual logger in its own class
    ILogger actualLogger = (ILogger) getFromField(clientLogger, "logger");
    Class<?> clientLoggerClass = actualLogger.getClass();
    ILogger expectedLogger = new Log4j2Factory().getLogger("expectedLogger");
    Class<?> expectedLoggerClass = expectedLogger.getClass();
    assertSame(expectedLoggerClass, clientLoggerClass);
}
Also used : Log4j2Factory(com.hazelcast.logging.Log4j2Factory) Config(com.hazelcast.config.Config) ClientConfig(com.hazelcast.client.config.ClientConfig) TestHazelcastFactory(com.hazelcast.client.test.TestHazelcastFactory) ILogger(com.hazelcast.logging.ILogger) ClientConfig(com.hazelcast.client.config.ClientConfig)

Example 5 with ILogger

use of com.hazelcast.logging.ILogger in project hazelcast by hazelcast.

the class AuthenticationBaseMessageTask method prepareUnauthenticatedClientMessage.

private ClientMessage prepareUnauthenticatedClientMessage() {
    Connection connection = endpoint.getConnection();
    ILogger logger = clientEngine.getLogger(getClass());
    logger.warning("Received auth from " + connection + " with principal " + principal + " , authentication failed");
    byte status = AuthenticationStatus.CREDENTIALS_FAILED.getId();
    return encodeAuth(status, null, null, null, serializationService.getVersion(), null);
}
Also used : Connection(com.hazelcast.nio.Connection) ILogger(com.hazelcast.logging.ILogger)

Aggregations

ILogger (com.hazelcast.logging.ILogger)76 Address (com.hazelcast.nio.Address)19 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)11 Node (com.hazelcast.instance.Node)10 InternalPartitionServiceImpl (com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl)10 NodeEngine (com.hazelcast.spi.NodeEngine)10 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)9 ReplicatedMapService (com.hazelcast.replicatedmap.impl.ReplicatedMapService)6 OperationService (com.hazelcast.spi.OperationService)6 IOException (java.io.IOException)4 Before (org.junit.Before)4 JsonObject (com.eclipsesource.json.JsonObject)3 ClientAwsConfig (com.hazelcast.client.config.ClientAwsConfig)3 Connection (com.hazelcast.nio.Connection)3 ReplicatedRecordStore (com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore)3 Operation (com.hazelcast.spi.Operation)3 HazelcastProperties (com.hazelcast.spi.properties.HazelcastProperties)3 JsonUtil.getString (com.hazelcast.util.JsonUtil.getString)3 ClientNetworkConfig (com.hazelcast.client.config.ClientNetworkConfig)2 ClusterState (com.hazelcast.cluster.ClusterState)2