sprint-1 - warmup closure cleanup.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/5fa6d5cb Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/5fa6d5cb Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/5fa6d5cb Branch: refs/heads/ignite-188 Commit: 5fa6d5cb40f7dcd57ad564faacab2a492eea8c1c Parents: 17d816f Author: Dmitiry Setrakyan <dsetrak...@gridgain.com> Authored: Thu Feb 5 19:51:40 2015 -0800 Committer: Dmitiry Setrakyan <dsetrak...@gridgain.com> Committed: Thu Feb 5 19:51:40 2015 -0800 ---------------------------------------------------------------------- .../singlesplit/SingleSplitsLoadTest.java | 2 +- .../gridify/GridifySingleSplitLoadTest.java | 2 +- .../router/TcpRouterAbstractSelfTest.java | 2 +- .../router/TcpRouterMultiNodeSelfTest.java | 2 +- .../processors/rest/TestBinaryClient.java | 2 +- .../processors/rest/TestMemcacheClient.java | 2 +- .../src/test/resources/spring-router-ssl.xml | 2 +- .../src/test/resources/spring-router.xml | 2 +- .../src/test/resources/spring-server-node.xml | 2 +- .../test/resources/spring-server-ssl-node.xml | 2 +- .../apache/ignite/IgniteBasicWarmupClosure.java | 560 ------------------- .../GridClientConnectionManagerAdapter.java | 2 +- .../client/router/impl/GridTcpRouterImpl.java | 2 +- .../org/apache/ignite/internal/IgnitionEx.java | 6 +- .../ignite/logger/IgniteLoggerNodeIdAware.java | 39 -- .../apache/ignite/logger/IgniteNullLogger.java | 91 --- .../apache/ignite/logger/LoggerNodeIdAware.java | 39 ++ .../org/apache/ignite/logger/NullLogger.java | 91 +++ .../ignite/logger/java/IgniteJavaLogger.java | 388 ------------- .../java/IgniteJavaLoggerFileHandler.java | 190 ------- .../logger/java/IgniteJavaLoggerFormatter.java | 79 --- .../apache/ignite/logger/java/JavaLogger.java | 388 +++++++++++++ .../logger/java/JavaLoggerFileHandler.java | 190 +++++++ .../ignite/logger/java/JavaLoggerFormatter.java | 79 +++ .../ignite/startup/BasicWarmupClosure.java | 4 +- .../internal/GridLifecycleAwareSelfTest.java | 2 +- ...artupWithSpecifiedWorkDirectorySelfTest.java | 4 +- ...tartupWithUndefinedGridGainHomeSelfTest.java | 2 +- .../ipc/shmem/GgfsSharedMemoryTestClient.java | 2 +- .../ipc/shmem/IpcSharedMemoryFakeClient.java | 6 +- .../IpcSharedMemoryBenchmarkWriter.java | 2 +- .../ignite/logger/java/GridJavaLoggerTest.java | 6 +- .../marshaller/GridMarshallerResourceBean.java | 2 +- .../logger/GridLog4jRollingFileAppender.java | 2 +- .../junits/logger/GridTestLog4jLogger.java | 6 +- .../child/GridHadoopExternalProcessStarter.java | 6 +- .../IgniteLog4jDailyRollingFileAppender.java | 2 +- ...IgniteLog4jExternallyRolledFileAppender.java | 2 +- .../logger/log4j/IgniteLog4jFileAppender.java | 2 +- .../ignite/logger/log4j/IgniteLog4jLogger.java | 522 ----------------- .../log4j/IgniteLog4jRollingFileAppender.java | 2 +- .../apache/ignite/logger/log4j/Log4JLogger.java | 522 +++++++++++++++++ .../log4j/GridLog4jCorrectFileNameTest.java | 4 +- .../logger/log4j/GridLog4jInitializedTest.java | 4 +- .../logger/log4j/GridLog4jLoggingFileTest.java | 2 +- .../logger/log4j/GridLog4jLoggingPathTest.java | 2 +- .../logger/log4j/GridLog4jLoggingUrlTest.java | 2 +- .../log4j/GridLog4jNotInitializedTest.java | 2 +- 48 files changed, 1358 insertions(+), 1918 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5fa6d5cb/modules/aop/src/test/java/org/apache/loadtests/direct/singlesplit/SingleSplitsLoadTest.java ---------------------------------------------------------------------- diff --git a/modules/aop/src/test/java/org/apache/loadtests/direct/singlesplit/SingleSplitsLoadTest.java b/modules/aop/src/test/java/org/apache/loadtests/direct/singlesplit/SingleSplitsLoadTest.java index a2b207e..124f0c4 100644 --- a/modules/aop/src/test/java/org/apache/loadtests/direct/singlesplit/SingleSplitsLoadTest.java +++ b/modules/aop/src/test/java/org/apache/loadtests/direct/singlesplit/SingleSplitsLoadTest.java @@ -50,7 +50,7 @@ public class SingleSplitsLoadTest extends GridCommonAbstractTest { cfg.setCommunicationSpi(new TcpCommunicationSpi()); cfg.setDiscoverySpi(new TcpDiscoverySpi()); - IgniteLog4jLogger log = (IgniteLog4jLogger)cfg.getGridLogger().getLogger(null); + Log4JLogger log = (Log4JLogger)cfg.getGridLogger().getLogger(null); log.setLevel(Level.INFO); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5fa6d5cb/modules/aop/src/test/java/org/apache/loadtests/gridify/GridifySingleSplitLoadTest.java ---------------------------------------------------------------------- diff --git a/modules/aop/src/test/java/org/apache/loadtests/gridify/GridifySingleSplitLoadTest.java b/modules/aop/src/test/java/org/apache/loadtests/gridify/GridifySingleSplitLoadTest.java index 5413932..9d470d3 100644 --- a/modules/aop/src/test/java/org/apache/loadtests/gridify/GridifySingleSplitLoadTest.java +++ b/modules/aop/src/test/java/org/apache/loadtests/gridify/GridifySingleSplitLoadTest.java @@ -69,7 +69,7 @@ public class GridifySingleSplitLoadTest extends GridCommonAbstractTest { /* */ @SuppressWarnings("TypeMayBeWeakened") - IgniteLog4jLogger log = (IgniteLog4jLogger)cfg.getGridLogger(); + Log4JLogger log = (Log4JLogger)cfg.getGridLogger(); log.getLogger("org.gridgain.grid").setLevel(Level.INFO); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5fa6d5cb/modules/clients/src/test/java/org/apache/ignite/client/router/TcpRouterAbstractSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/client/router/TcpRouterAbstractSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/client/router/TcpRouterAbstractSelfTest.java index c7175a2..677201e 100644 --- a/modules/clients/src/test/java/org/apache/ignite/client/router/TcpRouterAbstractSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/client/router/TcpRouterAbstractSelfTest.java @@ -107,7 +107,7 @@ public abstract class TcpRouterAbstractSelfTest extends ClientAbstractSelfTest { cfg.setPort(ROUTER_PORT); cfg.setPortRange(0); cfg.setServers(Collections.singleton(HOST+":"+BINARY_PORT)); - cfg.setLogger(new IgniteLog4jLogger(ROUTER_LOG_CFG)); + cfg.setLogger(new Log4JLogger(ROUTER_LOG_CFG)); return cfg; } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5fa6d5cb/modules/clients/src/test/java/org/apache/ignite/client/router/TcpRouterMultiNodeSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/client/router/TcpRouterMultiNodeSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/client/router/TcpRouterMultiNodeSelfTest.java index 359de9a..bb722fb 100644 --- a/modules/clients/src/test/java/org/apache/ignite/client/router/TcpRouterMultiNodeSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/client/router/TcpRouterMultiNodeSelfTest.java @@ -87,7 +87,7 @@ public class TcpRouterMultiNodeSelfTest extends ClientAbstractMultiNodeSelfTest cfg.setPort(ROUTER_TCP_PORT_BASE + i); cfg.setPortRange(0); cfg.setServers(Collections.singleton(HOST + ":" + REST_TCP_PORT_BASE)); - cfg.setLogger(new IgniteLog4jLogger(ROUTER_LOG_CFG)); + cfg.setLogger(new Log4JLogger(ROUTER_LOG_CFG)); return cfg; } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5fa6d5cb/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/TestBinaryClient.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/TestBinaryClient.java b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/TestBinaryClient.java index 9119bbd..0103622 100644 --- a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/TestBinaryClient.java +++ b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/TestBinaryClient.java @@ -41,7 +41,7 @@ import static org.apache.ignite.internal.processors.rest.client.message.GridClie */ final class TestBinaryClient { /** Logger. */ - private final IgniteLogger log = new IgniteJavaLogger(); + private final IgniteLogger log = new JavaLogger(); /** Marshaller. */ private final GridClientMarshaller marsh = new GridClientOptimizedMarshaller(); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5fa6d5cb/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/TestMemcacheClient.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/TestMemcacheClient.java b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/TestMemcacheClient.java index 2f61c5c..89c59ca 100644 --- a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/TestMemcacheClient.java +++ b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/TestMemcacheClient.java @@ -65,7 +65,7 @@ final class TestMemcacheClient { private static final short BYTE_ARR_FLAG = (8 << 8); /** Logger. */ - private final IgniteLogger log = new IgniteJavaLogger(); + private final IgniteLogger log = new JavaLogger(); /** JDK marshaller. */ private final IgniteMarshaller jdkMarshaller = new IgniteJdkMarshaller(); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5fa6d5cb/modules/clients/src/test/resources/spring-router-ssl.xml ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/resources/spring-router-ssl.xml b/modules/clients/src/test/resources/spring-router-ssl.xml index bf1a342..66fdbce 100644 --- a/modules/clients/src/test/resources/spring-router-ssl.xml +++ b/modules/clients/src/test/resources/spring-router-ssl.xml @@ -98,7 +98,7 @@ <!-- Logger with the same configuration as in default grid instances. --> - <bean id="router.log" class="org.apache.ignite.logger.log4j.IgniteLog4jLogger"> + <bean id="router.log" class="org.apache.ignite.logger.log4j.Log4JLogger"> <constructor-arg type="java.lang.String" value="modules/clients/src/test/resources/log4j.xml"/> </bean> </beans> http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5fa6d5cb/modules/clients/src/test/resources/spring-router.xml ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/resources/spring-router.xml b/modules/clients/src/test/resources/spring-router.xml index ba078f5..9d11b30 100644 --- a/modules/clients/src/test/resources/spring-router.xml +++ b/modules/clients/src/test/resources/spring-router.xml @@ -87,7 +87,7 @@ <!-- Logger with the same configuration as in default grid instances. --> - <bean id="router.log" class="org.apache.ignite.logger.log4j.IgniteLog4jLogger"> + <bean id="router.log" class="org.apache.ignite.logger.log4j.Log4JLogger"> <constructor-arg type="java.lang.String" value="modules/clients/src/test/resources/log4j.xml"/> </bean> </beans> http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5fa6d5cb/modules/clients/src/test/resources/spring-server-node.xml ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/resources/spring-server-node.xml b/modules/clients/src/test/resources/spring-server-node.xml index 3c450b8..4a02ce3 100644 --- a/modules/clients/src/test/resources/spring-server-node.xml +++ b/modules/clients/src/test/resources/spring-server-node.xml @@ -315,7 +315,7 @@ Logger to use. --> <property name="gridLogger"> - <bean class="org.apache.ignite.logger.log4j.IgniteLog4jLogger"> + <bean class="org.apache.ignite.logger.log4j.Log4JLogger"> <constructor-arg type="java.lang.String" value="modules/clients/src/test/resources/log4j.xml"/> </bean> </property> http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5fa6d5cb/modules/clients/src/test/resources/spring-server-ssl-node.xml ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/resources/spring-server-ssl-node.xml b/modules/clients/src/test/resources/spring-server-ssl-node.xml index 7769436..2e20670 100644 --- a/modules/clients/src/test/resources/spring-server-ssl-node.xml +++ b/modules/clients/src/test/resources/spring-server-ssl-node.xml @@ -282,7 +282,7 @@ Logger to use. --> <property name="gridLogger"> - <bean class="org.apache.ignite.logger.log4j.IgniteLog4jLogger"> + <bean class="org.apache.ignite.logger.log4j.Log4JLogger"> <constructor-arg type="java.lang.String" value="modules/clients/src/test/resources/log4j.xml"/> </bean> </property> http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5fa6d5cb/modules/core/src/main/java/org/apache/ignite/IgniteBasicWarmupClosure.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteBasicWarmupClosure.java b/modules/core/src/main/java/org/apache/ignite/IgniteBasicWarmupClosure.java deleted file mode 100644 index 8350f94..0000000 --- a/modules/core/src/main/java/org/apache/ignite/IgniteBasicWarmupClosure.java +++ /dev/null @@ -1,560 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite; - -import org.apache.ignite.cache.*; -import org.apache.ignite.configuration.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.lang.*; -import org.apache.ignite.logger.*; -import org.apache.ignite.spi.discovery.tcp.*; -import org.apache.ignite.spi.discovery.tcp.ipfinder.*; -import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; - -import java.text.*; -import java.util.*; -import java.util.concurrent.*; - -/** - * Basic warm-up closure which warm-ups cache operations. - */ -public class IgniteBasicWarmupClosure implements IgniteInClosure<IgniteConfiguration> { - /** */ - private static final long serialVersionUID = 9175346848249957458L; - - /** Default grid count to warm up. */ - public static final int DFLT_GRID_CNT = 2; - - /** Default iteration count per thread. */ - public static final int DFLT_ITERATION_CNT = 30_000; - - /** Default key range. */ - public static final int DFLT_KEY_RANGE = 10_000; - - /** Grid count. */ - private int gridCnt = DFLT_GRID_CNT; - - /** Warmup date format. */ - private static final SimpleDateFormat WARMUP_DATE_FMT = new SimpleDateFormat("HH:mm:ss"); - - /** Warmup thread count. */ - private int threadCnt = Runtime.getRuntime().availableProcessors() * 2; - - /** Per thread iteration count. */ - private int iterCnt = DFLT_ITERATION_CNT; - - /** Key range. */ - private int keyRange = DFLT_KEY_RANGE; - - /** Warmup discovery port. */ - private int discoveryPort = 27000; - - /** Methods to warmup. */ - private String[] warmupMethods = {"put", "putx", "get", "remove", "removex", "putIfAbsent", "replace"}; - - /** - * Gets number of grids to start and run warmup. - * - * @return Number of grids. - */ - public int getGridCount() { - return gridCnt; - } - - /** - * Sets number of grids to start and run the warmup. - * - * @param gridCnt Number of grids. - */ - public void setGridCount(int gridCnt) { - this.gridCnt = gridCnt; - } - - /** - * Gets warmup methods to use for cache warmup. - * - * @return Warmup methods. - */ - public String[] getWarmupMethods() { - return warmupMethods; - } - - /** - * Sets warmup methods to use for cache warmup. - * - * @param warmupMethods Array of warmup methods. - */ - public void setWarmupMethods(String... warmupMethods) { - this.warmupMethods = warmupMethods; - } - - /** - * Gets thread count for warmup. - * - * @return Thread count. - */ - public int getThreadCount() { - return threadCnt; - } - - /** - * Sets thread count for warmup. - * - * @param threadCnt Thread count. - */ - public void setThreadCount(int threadCnt) { - this.threadCnt = threadCnt; - } - - /** - * Gets iteration count for warmup. - * - * @return Iteration count. - */ - public int getIterationCount() { - return iterCnt; - } - - /** - * Sets iteration count for warmup. - * - * @param iterCnt Iteration count for warmup. - */ - public void setIterationCount(int iterCnt) { - this.iterCnt = iterCnt; - } - - /** - * Gets key range. - * - * @return Key range. - */ - public int getKeyRange() { - return keyRange; - } - - /** - * Sets key range. - * - * @param keyRange Key range. - */ - public void setKeyRange(int keyRange) { - this.keyRange = keyRange; - } - - /** - * Gets discovery port for warmup. - * - * @return Discovery port. - */ - public int getDiscoveryPort() { - return discoveryPort; - } - - /** - * Sets discovery port for warmup. - * - * @param discoveryPort Discovery port. - */ - public void setDiscoveryPort(int discoveryPort) { - this.discoveryPort = discoveryPort; - } - - /** {@inheritDoc} */ - @Override public void apply(IgniteConfiguration gridCfg) { - // Remove cache duplicates, clean up the rest, etc. - IgniteConfiguration cfg = prepareConfiguration(gridCfg); - - // Do nothing if no caches found. - if (cfg == null) - return; - - out("Starting grids to warmup caches [gridCnt=" + gridCnt + - ", caches=" + cfg.getCacheConfiguration().length + ']'); - - Collection<Ignite> ignites = new LinkedList<>(); - - String old = System.getProperty(IgniteSystemProperties.IGNITE_UPDATE_NOTIFIER); - - try { - System.setProperty(IgniteSystemProperties.IGNITE_UPDATE_NOTIFIER, "false"); - - TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); - - for (int i = 0; i < gridCnt; i++) { - IgniteConfiguration cfg0 = new IgniteConfiguration(cfg); - - TcpDiscoverySpi discoSpi = new TcpDiscoverySpi(); - - discoSpi.setIpFinder(ipFinder); - - discoSpi.setLocalPort(discoveryPort); - - cfg0.setDiscoverySpi(discoSpi); - - cfg0.setGridLogger(new IgniteNullLogger()); - - cfg0.setGridName("ignite-warmup-grid-" + i); - - ignites.add(Ignition.start(cfg0)); - } - - doWarmup(ignites); - } - catch (Exception e) { - throw new IgniteException(e); - } - finally { - for (Ignite ignite : ignites) - Ignition.stop(ignite.name(), false); - - out("Stopped warmup grids."); - - if (old == null) - old = "false"; - - System.setProperty(IgniteSystemProperties.IGNITE_UPDATE_NOTIFIER, old); - } - } - - /** - * @param grids Grids to warmup. - */ - private void doWarmup(Iterable<Ignite> grids) throws Exception { - Ignite first = F.first(grids); - - ExecutorService svc = Executors.newFixedThreadPool(threadCnt); - - try { - for (GridCache<?, ?> cache : first.caches()) { - GridCache<Object, Object> cache0 = first.cache(cache.name()); - - for (String warmupMethod : warmupMethods) { - Collection<Future> futs = new ArrayList<>(threadCnt); - - for (int i = 0; i < threadCnt; i++) { - Callable call; - - switch (warmupMethod) { - case "get": { - call = new GetCallable(cache0); - - break; - } - - case "put": { - call = new PutCallable(cache0); - - break; - } - - case "putx": { - call = new PutxCallable(cache0); - - break; - } - - case "remove": { - call = new RemoveCallable(cache0); - - break; - } - - case "removex": { - call = new RemovexCallable(cache0); - - break; - } - - case "putIfAbsent": { - call = new PutIfAbsentCallable(cache0); - - break; - } - - case "replace": { - call = new ReplaceCallable(cache0); - - break; - } - - default: - throw new IgniteCheckedException("Unsupported warmup method: " + warmupMethod); - } - - futs.add(svc.submit(call)); - } - - out("Running warmup [cacheName=" + cache.name() + ", method=" + warmupMethod + ']'); - - for (Future fut : futs) - fut.get(); - - for (int key = 0; key < keyRange; key++) - cache0.remove(key); - } - } - } - finally { - svc.shutdownNow(); - } - } - - /** - * Output for warmup messages. - * - * @param msg Format message. - */ - private static void out(String msg) { - System.out.println('[' + WARMUP_DATE_FMT.format(new Date(System.currentTimeMillis())) + "][WARMUP][" + - Thread.currentThread().getName() + ']' + ' ' + msg); - } - - /** - * Prepares configuration for warmup. - * - * @param gridCfg Original grid configuration. - * @return Prepared configuration or {@code null} if no caches found. - */ - private IgniteConfiguration prepareConfiguration(IgniteConfiguration gridCfg) { - if (F.isEmpty(gridCfg.getCacheConfiguration())) - return null; - - IgniteConfiguration cp = new IgniteConfiguration(); - - cp.setClientConnectionConfiguration(null); - - Collection<CacheConfiguration> reduced = new ArrayList<>(); - - for (CacheConfiguration ccfg : gridCfg.getCacheConfiguration()) { - if (CU.isSystemCache(ccfg.getName())) - continue; - - if (!matches(reduced, ccfg)) { - CacheConfiguration ccfgCp = new CacheConfiguration(ccfg); - - if (ccfgCp.getDistributionMode() == CacheDistributionMode.CLIENT_ONLY) - ccfgCp.setDistributionMode(CacheDistributionMode.PARTITIONED_ONLY); - else if (ccfgCp.getDistributionMode() == CacheDistributionMode.NEAR_ONLY) - ccfgCp.setDistributionMode(CacheDistributionMode.NEAR_PARTITIONED); - - ccfgCp.setCacheStoreFactory(null); - ccfgCp.setWriteBehindEnabled(false); - - reduced.add(ccfgCp); - } - } - - if (F.isEmpty(reduced)) - return null; - - CacheConfiguration[] res = new CacheConfiguration[reduced.size()]; - - reduced.toArray(res); - - cp.setCacheConfiguration(res); - - return cp; - } - - /** - * Checks if passed configuration matches one of the configurations in the list. - * - * @param reduced Reduced configurations. - * @param ccfg Cache configuration to match. - * @return {@code True} if matching configuration is found, {@code false} otherwise. - */ - private boolean matches(Iterable<CacheConfiguration> reduced, CacheConfiguration ccfg) { - for (CacheConfiguration ccfg0 : reduced) { - if (matches(ccfg0, ccfg)) - return true; - } - - return false; - } - - /** - * Checks if cache configurations are alike for warmup. - * - * @param ccfg0 First configuration. - * @param ccfg1 Second configuration. - * @return {@code True} if configurations match. - */ - private boolean matches(CacheConfiguration ccfg0, CacheConfiguration ccfg1) { - return - F.eq(ccfg0.getCacheMode(), ccfg1.getCacheMode()) && - F.eq(ccfg0.getBackups(), ccfg1.getBackups()) && - F.eq(ccfg0.getAtomicityMode(), ccfg1.getAtomicityMode()) && - F.eq(ccfg0.getAtomicWriteOrderMode(), ccfg1.getAtomicWriteOrderMode()) && - F.eq(ccfg0.getMemoryMode(), ccfg1.getMemoryMode()) && - F.eq(ccfg0.getDistributionMode(), ccfg1.getDistributionMode()); - } - - /** - * Base class for all warmup callables. - */ - private abstract class BaseWarmupCallable implements Callable<Object> { - /** Cache. */ - protected final GridCache<Object, Object> cache; - - /** - * @param cache Cache. - */ - protected BaseWarmupCallable(GridCache<Object, Object> cache) { - this.cache = cache; - } - - /** {@inheritDoc} */ - @Override public Object call() throws Exception { - ThreadLocalRandom rnd = ThreadLocalRandom.current(); - - for (int i = 0; i < iterCnt; i++) - operation(rnd.nextInt(keyRange)); - - return null; - } - - /** - * Runs operation. - * - * @param key Key. - * @throws Exception If failed. - */ - protected abstract void operation(int key) throws Exception; - } - - /** - * - */ - private class GetCallable extends BaseWarmupCallable { - /** - * @param cache Cache. - */ - private GetCallable(GridCache<Object, Object> cache) { - super(cache); - } - - /** {@inheritDoc} */ - @Override protected void operation(int key) throws Exception { - cache.get(key); - } - } - - /** - * - */ - private class PutCallable extends BaseWarmupCallable { - /** - * @param cache Cache. - */ - private PutCallable(GridCache<Object, Object> cache) { - super(cache); - } - - /** {@inheritDoc} */ - @Override protected void operation(int key) throws Exception { - cache.put(key, key); - } - } - - /** - * - */ - private class PutxCallable extends BaseWarmupCallable { - /** - * @param cache Cache. - */ - private PutxCallable(GridCache<Object, Object> cache) { - super(cache); - } - - /** {@inheritDoc} */ - @Override protected void operation(int key) throws Exception { - cache.putx(key, key); - } - } - - /** - * - */ - private class RemoveCallable extends BaseWarmupCallable { - /** - * @param cache Cache. - */ - private RemoveCallable(GridCache<Object, Object> cache) { - super(cache); - } - - /** {@inheritDoc} */ - @Override protected void operation(int key) throws Exception { - cache.remove(key); - } - } - - /** - * - */ - private class RemovexCallable extends BaseWarmupCallable { - /** - * @param cache Cache. - */ - private RemovexCallable(GridCache<Object, Object> cache) { - super(cache); - } - - /** {@inheritDoc} */ - @Override protected void operation(int key) throws Exception { - cache.removex(key); - } - } - - /** - * - */ - private class PutIfAbsentCallable extends BaseWarmupCallable { - /** - * @param cache Cache. - */ - private PutIfAbsentCallable(GridCache<Object, Object> cache) { - super(cache); - } - - /** {@inheritDoc} */ - @Override protected void operation(int key) throws Exception { - cache.putIfAbsent(key, key); - } - } - - /** - * - */ - private class ReplaceCallable extends BaseWarmupCallable { - /** - * @param cache Cache. - */ - private ReplaceCallable(GridCache<Object, Object> cache) { - super(cache); - } - - /** {@inheritDoc} */ - @Override protected void operation(int key) throws Exception { - cache.replace(key, key, key); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5fa6d5cb/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientConnectionManagerAdapter.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientConnectionManagerAdapter.java b/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientConnectionManagerAdapter.java index 2e6ca2b..d77908e 100644 --- a/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientConnectionManagerAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientConnectionManagerAdapter.java @@ -176,7 +176,7 @@ abstract class GridClientConnectionManagerAdapter implements GridClientConnectio if (cfg.getProtocol() == GridClientProtocol.TCP) { try { - IgniteLogger gridLog = new IgniteJavaLogger(false); + IgniteLogger gridLog = new JavaLogger(false); GridNioFilter[] filters; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5fa6d5cb/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridTcpRouterImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridTcpRouterImpl.java b/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridTcpRouterImpl.java index 8cfae95..0c1b651 100644 --- a/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridTcpRouterImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridTcpRouterImpl.java @@ -80,7 +80,7 @@ public class GridTcpRouterImpl implements GridTcpRouter, GridTcpRouterMBean, Lif this.cfg = cfg; log = cfg.getLogger() != null ? - cfg.getLogger().getLogger(getClass()) : new IgniteJavaLogger().getLogger(getClass()); + cfg.getLogger().getLogger(getClass()) : new JavaLogger().getLogger(getClass()); } /** http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5fa6d5cb/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java index 05999ee..c5c1c25 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java @@ -2085,12 +2085,12 @@ public class IgnitionEx { } if (log4jCls == null || log4jInitErr != null) - cfgLog = new IgniteJavaLogger(); + cfgLog = new JavaLogger(); } // Set node IDs for all file appenders. - if (cfgLog instanceof IgniteLoggerNodeIdAware) - ((IgniteLoggerNodeIdAware)cfgLog).setNodeId(nodeId); + if (cfgLog instanceof LoggerNodeIdAware) + ((LoggerNodeIdAware)cfgLog).setNodeId(nodeId); if (log4jInitErr != null) U.warn(cfgLog, "Failed to initialize IgniteLog4jLogger (falling back to standard java logging): " http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5fa6d5cb/modules/core/src/main/java/org/apache/ignite/logger/IgniteLoggerNodeIdAware.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/logger/IgniteLoggerNodeIdAware.java b/modules/core/src/main/java/org/apache/ignite/logger/IgniteLoggerNodeIdAware.java deleted file mode 100644 index 04a0166..0000000 --- a/modules/core/src/main/java/org/apache/ignite/logger/IgniteLoggerNodeIdAware.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.logger; - -import java.util.*; - -/** - * Interface for GridGain file appenders to attach node ID to log file names. - */ -public interface IgniteLoggerNodeIdAware { - /** - * Sets node ID. - * - * @param nodeId Node ID. - */ - public void setNodeId(UUID nodeId); - - /** - * Gets node ID. - * - * @return Node ID. - */ - public UUID getNodeId(); -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5fa6d5cb/modules/core/src/main/java/org/apache/ignite/logger/IgniteNullLogger.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/logger/IgniteNullLogger.java b/modules/core/src/main/java/org/apache/ignite/logger/IgniteNullLogger.java deleted file mode 100644 index b45f5c4..0000000 --- a/modules/core/src/main/java/org/apache/ignite/logger/IgniteNullLogger.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.logger; - -import org.apache.ignite.*; -import org.jetbrains.annotations.*; - -/** - * Logger which does not output anything. - */ -public class IgniteNullLogger implements IgniteLogger { - /** {@inheritDoc} */ - @Override public IgniteLogger getLogger(Object ctgr) { - return this; - } - - /** {@inheritDoc} */ - @Override public void trace(String msg) { - // No-op. - } - - /** {@inheritDoc} */ - @Override public void debug(String msg) { - // No-op. - } - - /** {@inheritDoc} */ - @Override public void info(String msg) { - // No-op. - } - - /** {@inheritDoc} */ - @Override public void warning(String msg) { - // No-op. - } - - /** {@inheritDoc} */ - @Override public void warning(String msg, @Nullable Throwable e) { - // No-op. - } - - /** {@inheritDoc} */ - @Override public void error(String msg) { - // No-op. - } - - /** {@inheritDoc} */ - @Override public void error(String msg, @Nullable Throwable e) { - // No-op. - } - - /** {@inheritDoc} */ - @Override public boolean isTraceEnabled() { - return false; - } - - /** {@inheritDoc} */ - @Override public boolean isDebugEnabled() { - return false; - } - - /** {@inheritDoc} */ - @Override public boolean isInfoEnabled() { - return false; - } - - /** {@inheritDoc} */ - @Override public boolean isQuiet() { - return false; - } - - /** {@inheritDoc} */ - @Nullable @Override public String fileName() { - return null; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5fa6d5cb/modules/core/src/main/java/org/apache/ignite/logger/LoggerNodeIdAware.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/logger/LoggerNodeIdAware.java b/modules/core/src/main/java/org/apache/ignite/logger/LoggerNodeIdAware.java new file mode 100644 index 0000000..1250436 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/logger/LoggerNodeIdAware.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.logger; + +import java.util.*; + +/** + * Interface for GridGain file appenders to attach node ID to log file names. + */ +public interface LoggerNodeIdAware { + /** + * Sets node ID. + * + * @param nodeId Node ID. + */ + public void setNodeId(UUID nodeId); + + /** + * Gets node ID. + * + * @return Node ID. + */ + public UUID getNodeId(); +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5fa6d5cb/modules/core/src/main/java/org/apache/ignite/logger/NullLogger.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/logger/NullLogger.java b/modules/core/src/main/java/org/apache/ignite/logger/NullLogger.java new file mode 100644 index 0000000..b30c365 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/logger/NullLogger.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.logger; + +import org.apache.ignite.*; +import org.jetbrains.annotations.*; + +/** + * Logger which does not output anything. + */ +public class NullLogger implements IgniteLogger { + /** {@inheritDoc} */ + @Override public IgniteLogger getLogger(Object ctgr) { + return this; + } + + /** {@inheritDoc} */ + @Override public void trace(String msg) { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void debug(String msg) { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void info(String msg) { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void warning(String msg) { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void warning(String msg, @Nullable Throwable e) { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void error(String msg) { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void error(String msg, @Nullable Throwable e) { + // No-op. + } + + /** {@inheritDoc} */ + @Override public boolean isTraceEnabled() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean isDebugEnabled() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean isInfoEnabled() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean isQuiet() { + return false; + } + + /** {@inheritDoc} */ + @Nullable @Override public String fileName() { + return null; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5fa6d5cb/modules/core/src/main/java/org/apache/ignite/logger/java/IgniteJavaLogger.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/logger/java/IgniteJavaLogger.java b/modules/core/src/main/java/org/apache/ignite/logger/java/IgniteJavaLogger.java deleted file mode 100644 index 38c17e1..0000000 --- a/modules/core/src/main/java/org/apache/ignite/logger/java/IgniteJavaLogger.java +++ /dev/null @@ -1,388 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.logger.java; - -import org.apache.ignite.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.logger.*; -import org.jetbrains.annotations.*; - -import java.io.*; -import java.net.*; -import java.util.*; -import java.util.logging.*; - -import static java.util.logging.Level.*; -import static org.apache.ignite.IgniteSystemProperties.*; - -/** - * Logger to use with Java logging. Implementation simply delegates to Java Logging. - * <p> - * Here is an example of configuring Java logger in GridGain configuration Spring - * file to work over log4j implementation. Note that we use the same configuration file - * as we provide by default: - * <pre name="code" class="xml"> - * ... - * <property name="gridLogger"> - * <bean class="org.gridgain.grid.logger.java.GridJavaLogger"> - * <constructor-arg type="java.util.logging.Logger"> - * <bean class="java.util.logging.Logger"> - * <constructor-arg type="java.lang.String" value="global"/> - * </bean> - * </constructor-arg> - * </bean> - * </property> - * ... - * </pre> - * or - * <pre name="code" class="xml"> - * ... - * <property name="gridLogger"> - * <bean class="org.gridgain.grid.logger.java.GridJavaLogger"/> - * </property> - * ... - * </pre> - * And the same configuration if you'd like to configure GridGain in your code: - * <pre name="code" class="java"> - * GridConfiguration cfg = new GridConfiguration(); - * ... - * GridLogger log = new GridJavaLogger(Logger.global); - * ... - * cfg.setGridLogger(log); - * </pre> - * or which is actually the same: - * <pre name="code" class="java"> - * GridConfiguration cfg = new GridConfiguration(); - * ... - * GridLogger log = new GridJavaLogger(); - * ... - * cfg.setGridLogger(log); - * </pre> - * Please take a look at <a target=_new href="http://java.sun.com/j2se/1.4.2/docs/api20/java/util/logging/Logger.html">Logger javadoc</a> - * for additional information. - * <p> - * It's recommended to use GridGain logger injection instead of using/instantiating - * logger in your task/job code. See {@link org.apache.ignite.resources.IgniteLoggerResource} annotation about logger - * injection. - */ -public class IgniteJavaLogger implements IgniteLogger, IgniteLoggerNodeIdAware { - /** */ - private static final long serialVersionUID = 0L; - - /** */ - public static final String DFLT_CONFIG_PATH = "config/java.util.logging.properties"; - - /** */ - private static final Object mux = new Object(); - - /** */ - private static volatile boolean inited; - - /** */ - private static volatile boolean quiet0; - - /** Java Logging implementation proxy. */ - @SuppressWarnings("FieldAccessedSynchronizedAndUnsynchronized") - private Logger impl; - - /** Quiet flag. */ - private final boolean quiet; - - /** Node ID. */ - private volatile UUID nodeId; - - /** - * Creates new logger. - */ - public IgniteJavaLogger() { - this(!isConfigured()); - } - - /** - * Checks if logger is already configured within this VM or not. - * - * @return {@code True} if logger was already configured, {@code false} otherwise. - */ - public static boolean isConfigured() { - return System.getProperty("java.util.logging.config.file") != null; - } - - /** - * Reads default JUL configuration. - */ - private void defaultConfiguration() { - final URL cfgUrl = U.resolveGridGainUrl(DFLT_CONFIG_PATH); - - if (cfgUrl == null) { - error("Failed to resolve default logging config file: " + DFLT_CONFIG_PATH); - - return; - } - - try (InputStream in = cfgUrl.openStream()) { - LogManager.getLogManager().readConfiguration(in); - } - catch (IOException e) { - error("Failed to read logging configuration: " + cfgUrl, e); - } - } - - /** - * Creates new logger. - * - * @param init If {@code true}, then a default console appender will be created. - * If {@code false}, then no implicit initialization will take place, - * and java logger should be configured prior to calling this constructor. - */ - public IgniteJavaLogger(boolean init) { - impl = Logger.getLogger(""); - - if (init) { - // Implementation has already been inited, passing NULL. - configure(null); - - quiet = quiet0; - } - else - quiet = true; - } - - /** - * Creates new logger with given implementation. - * - * @param impl Java Logging implementation to use. - */ - public IgniteJavaLogger(final Logger impl) { - assert impl != null; - - configure(impl); - - quiet = quiet0; - } - - /** {@inheritDoc} */ - @Override public IgniteLogger getLogger(Object ctgr) { - return new IgniteJavaLogger(ctgr == null ? Logger.getLogger("") : Logger.getLogger( - ctgr instanceof Class ? ((Class)ctgr).getName() : String.valueOf(ctgr))); - } - - /** - * Configures handlers when needed. - * - * @param initImpl Optional log implementation. - */ - private void configure(@Nullable Logger initImpl) { - if (initImpl != null) - impl = initImpl; - - if (inited) - return; - - synchronized (mux) { - if (inited) - return; - - if (isConfigured()) { - boolean consoleHndFound = findHandler(impl, ConsoleHandler.class) != null; - - // User configured console appender, thus log is not quiet. - quiet0 = !consoleHndFound; - inited = true; - - return; - } - - defaultConfiguration(); - - boolean quiet = Boolean.valueOf(System.getProperty(IGNITE_QUIET, "true")); - boolean useConsoleAppender = Boolean.valueOf(System.getProperty(IGNITE_CONSOLE_APPENDER, "true")); - - if (useConsoleAppender) { - ConsoleHandler consoleHnd = findHandler(impl, ConsoleHandler.class); - - if (consoleHnd != null) - consoleHnd.setLevel(quiet ? SEVERE : INFO); - else - System.err.println("Console logging handler is not configured."); - } - else { - Handler[] handlers = Logger.getLogger("").getHandlers(); - - if (!F.isEmpty(handlers)) { - for (Handler h : handlers) { - if (h instanceof ConsoleHandler) - impl.removeHandler(h); - } - } - } - - quiet0 = quiet; - inited = true; - } - } - - /** {@inheritDoc} */ - @Override public void trace(String msg) { - if (!impl.isLoggable(FINEST)) - warning("Logging at TRACE level without checking if TRACE level is enabled: " + msg); - - impl.finest(msg); - } - - /** {@inheritDoc} */ - @Override public void debug(String msg) { - if (!impl.isLoggable(FINE)) - warning("Logging at DEBUG level without checking if DEBUG level is enabled: " + msg); - - impl.fine(msg); - } - - /** {@inheritDoc} */ - @Override public void info(String msg) { - if (!impl.isLoggable(INFO)) - warning("Logging at INFO level without checking if INFO level is enabled: " + msg); - - impl.info(msg); - } - - /** {@inheritDoc} */ - @Override public void warning(String msg) { - impl.warning(msg); - } - - /** {@inheritDoc} */ - @Override public void warning(String msg, @Nullable Throwable e) { - impl.log(WARNING, msg, e); - } - - /** {@inheritDoc} */ - @Override public void error(String msg) { - impl.severe(msg); - } - - /** {@inheritDoc} */ - @Override public boolean isQuiet() { - return quiet; - } - - /** {@inheritDoc} */ - @Override public void error(String msg, @Nullable Throwable e) { - impl.log(SEVERE, msg, e); - } - - /** {@inheritDoc} */ - @Override public boolean isTraceEnabled() { - return impl.isLoggable(FINEST); - } - - /** {@inheritDoc} */ - @Override public boolean isDebugEnabled() { - return impl.isLoggable(FINE); - } - - /** {@inheritDoc} */ - @Override public boolean isInfoEnabled() { - return impl.isLoggable(INFO); - } - - /** {@inheritDoc} */ - @Nullable @Override public String fileName() { - IgniteJavaLoggerFileHandler gridFileHnd = findHandler(impl, IgniteJavaLoggerFileHandler.class); - - if (gridFileHnd != null) - return gridFileHnd.fileName(); - - FileHandler fileHnd = findHandler(impl, FileHandler.class); - - return fileName(fileHnd); - } - - /** - * @param fileHnd File handler. - * @return Current log file or {@code null} if it can not be retrieved from file handler. - */ - @Nullable static String fileName(FileHandler fileHnd) { - if (fileHnd == null) - return null; - - try { - File[] logFiles = U.field(fileHnd, "files"); - - return logFiles[0].getAbsolutePath(); - } - catch (Exception ignored) { - return null; - } - } - - /** {@inheritDoc} */ - @Override public void setNodeId(UUID nodeId) { - A.notNull(nodeId, "nodeId"); - - if (this.nodeId != null) - return; - - synchronized (mux) { - // Double check. - if (this.nodeId != null) - return; - - this.nodeId = nodeId; - } - - IgniteJavaLoggerFileHandler fileHnd = findHandler(impl, IgniteJavaLoggerFileHandler.class); - - if (fileHnd == null) - return; - - try { - fileHnd.nodeId(nodeId); - } - catch (IgniteCheckedException | IOException e) { - throw new RuntimeException("Failed to enable file handler.", e); - } - } - - /** {@inheritDoc} */ - @Override public UUID getNodeId() { - return nodeId; - } - - /** - * Returns first found handler of specified class type or {@code null} if that handler isn't configured. - * - * @param log Logger. - * @param cls Class. - * @param <T> Class type. - * @return First found handler of specified class type or {@code null} if that handler isn't configured. - */ - @SuppressWarnings("unchecked") - private static <T> T findHandler(Logger log, Class<T> cls) { - while (log != null) { - for (Handler hnd : log.getHandlers()) { - if (cls.isInstance(hnd)) - return (T)hnd; - } - - log = log.getParent(); - } - - return null; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5fa6d5cb/modules/core/src/main/java/org/apache/ignite/logger/java/IgniteJavaLoggerFileHandler.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/logger/java/IgniteJavaLoggerFileHandler.java b/modules/core/src/main/java/org/apache/ignite/logger/java/IgniteJavaLoggerFileHandler.java deleted file mode 100644 index 5e23fb5..0000000 --- a/modules/core/src/main/java/org/apache/ignite/logger/java/IgniteJavaLoggerFileHandler.java +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.logger.java; - -import org.apache.ignite.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.jetbrains.annotations.*; - -import java.io.*; -import java.util.*; -import java.util.logging.*; - -/** - * File logging handler which skips all the messages until node ID is set. - */ -public final class IgniteJavaLoggerFileHandler extends StreamHandler { - /** Log manager. */ - private static final LogManager manager = LogManager.getLogManager(); - - /** Handler delegate. */ - private volatile FileHandler delegate; - - /** {@inheritDoc} */ - @SuppressWarnings("NonSynchronizedMethodOverridesSynchronizedMethod") - @Override public void publish(LogRecord record) { - FileHandler delegate0 = delegate; - - if (delegate0 != null) - delegate0.publish(record); - } - - /** {@inheritDoc} */ - @SuppressWarnings("NonSynchronizedMethodOverridesSynchronizedMethod") - @Override public void flush() { - FileHandler delegate0 = delegate; - - if (delegate0 != null) - delegate0.flush(); - } - - /** {@inheritDoc} */ - @SuppressWarnings("NonSynchronizedMethodOverridesSynchronizedMethod") - @Override public void close() throws SecurityException { - FileHandler delegate0 = delegate; - - if (delegate0 != null) - delegate0.close(); - } - - /** {@inheritDoc} */ - @SuppressWarnings("NonSynchronizedMethodOverridesSynchronizedMethod") - @Override public boolean isLoggable(LogRecord record) { - FileHandler delegate0 = delegate; - - return delegate0 != null && delegate0.isLoggable(record); - } - - /** - * Sets Node id and instantiates {@link FileHandler} delegate. - * - * @param nodeId Node id. - */ - public void nodeId(UUID nodeId) throws IgniteCheckedException, IOException { - if (delegate != null) - return; - - String clsName = getClass().getName(); - - String ptrn = manager.getProperty(clsName + ".pattern"); - - if (ptrn == null) - ptrn = "ignite-%{id8}.%g.log"; - - ptrn = new File(logDirectory(), ptrn.replace("%{id8}", U.id8(nodeId))).getAbsolutePath(); - - int limit = getIntProperty(clsName + ".limit", 0); - - if (limit < 0) - limit = 0; - - int cnt = getIntProperty(clsName + ".count", 1); - - if (cnt <= 0) - cnt = 1; - - boolean append = getBooleanProperty(clsName + ".append", false); - - FileHandler delegate0; - - synchronized (this) { - if (delegate != null) - return; - - delegate = delegate0 = new FileHandler(ptrn, limit, cnt, append); - } - - delegate0.setLevel(getLevel()); - delegate0.setFormatter(getFormatter()); - delegate0.setEncoding(getEncoding()); - delegate0.setFilter(getFilter()); - delegate0.setErrorManager(getErrorManager()); - } - - /** - * Returns current log file. - * - * @return Pattern or {@code null} if node id has not been set yet. - */ - @Nullable public String fileName() { - return IgniteJavaLogger.fileName(delegate); - } - - /** - * Resolves logging directory. - * - * @return Logging directory. - */ - private static File logDirectory() throws IgniteCheckedException { - return !F.isEmpty(U.IGNITE_LOG_DIR) ? new File(U.IGNITE_LOG_DIR) : U.resolveWorkDirectory("log", false); - } - - /** - * Returns integer property from logging configuration. - * - * @param name Property name. - * @param dfltVal Default value. - * @return Parsed property value if it is set and valid or default value otherwise. - */ - private int getIntProperty(String name, int dfltVal) { - String val = manager.getProperty(name); - - if (val == null) - return dfltVal; - - try { - return Integer.parseInt(val.trim()); - } - catch (Exception ex) { - ex.printStackTrace(); - - return dfltVal; - } - } - - /** - * Returns boolean property from logging configuration. - * - * @param name Property name. - * @param dfltVal Default value. - * @return Parsed property value if it is set and valid or default value otherwise. - */ - @SuppressWarnings("SimplifiableIfStatement") - private boolean getBooleanProperty(String name, boolean dfltVal) { - String val = manager.getProperty(name); - - if (val == null) - return dfltVal; - - val = val.toLowerCase(); - - if ("true".equals(val) || "1".equals(val)) - return true; - - if ("false".equals(val) || "0".equals(val)) - return false; - - return dfltVal; - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(IgniteJavaLoggerFileHandler.class, this); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5fa6d5cb/modules/core/src/main/java/org/apache/ignite/logger/java/IgniteJavaLoggerFormatter.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/logger/java/IgniteJavaLoggerFormatter.java b/modules/core/src/main/java/org/apache/ignite/logger/java/IgniteJavaLoggerFormatter.java deleted file mode 100644 index 5cb0daf..0000000 --- a/modules/core/src/main/java/org/apache/ignite/logger/java/IgniteJavaLoggerFormatter.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.logger.java; - -import org.apache.ignite.internal.util.typedef.internal.*; - -import java.io.*; -import java.text.*; -import java.util.*; -import java.util.logging.Formatter; -import java.util.logging.*; - -/** - * Formatter for JUL logger. - */ -public class IgniteJavaLoggerFormatter extends Formatter { - /** Name for anonymous loggers. */ - public static final String ANONYMOUS_LOGGER_NAME = "UNKNOWN"; - - /** */ - private static final ThreadLocal<SimpleDateFormat> DATE_FORMATTER = new ThreadLocal<SimpleDateFormat>() { - /** {@inheritDoc} */ - @Override protected SimpleDateFormat initialValue() { - return new SimpleDateFormat("HH:mm:ss,SSS"); - } - }; - - /** {@inheritDoc} */ - @SuppressWarnings("ThrowableResultOfMethodCallIgnored") - @Override public String format(LogRecord record) { - String threadName = Thread.currentThread().getName(); - - String logName = record.getLoggerName(); - - if (logName == null) - logName = ANONYMOUS_LOGGER_NAME; - else if (logName.contains(".")) - logName = logName.substring(logName.lastIndexOf('.') + 1); - - String ex = null; - - if (record.getThrown() != null) { - StringWriter sw = new StringWriter(); - - record.getThrown().printStackTrace(new PrintWriter(sw)); - - String stackTrace = sw.toString(); - - ex = "\n" + stackTrace; - } - - return "[" + DATE_FORMATTER.get().format(new Date(record.getMillis())) + "][" + - record.getLevel() + "][" + - threadName + "][" + - logName + "] " + - record.getMessage() + - (ex == null ? "\n" : ex); - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(IgniteJavaLoggerFormatter.class, this); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5fa6d5cb/modules/core/src/main/java/org/apache/ignite/logger/java/JavaLogger.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/logger/java/JavaLogger.java b/modules/core/src/main/java/org/apache/ignite/logger/java/JavaLogger.java new file mode 100644 index 0000000..2c120a3 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/logger/java/JavaLogger.java @@ -0,0 +1,388 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.logger.java; + +import org.apache.ignite.*; +import org.apache.ignite.internal.util.typedef.*; +import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.logger.*; +import org.jetbrains.annotations.*; + +import java.io.*; +import java.net.*; +import java.util.*; +import java.util.logging.*; + +import static java.util.logging.Level.*; +import static org.apache.ignite.IgniteSystemProperties.*; + +/** + * Logger to use with Java logging. Implementation simply delegates to Java Logging. + * <p> + * Here is an example of configuring Java logger in GridGain configuration Spring + * file to work over log4j implementation. Note that we use the same configuration file + * as we provide by default: + * <pre name="code" class="xml"> + * ... + * <property name="gridLogger"> + * <bean class="org.gridgain.grid.logger.java.GridJavaLogger"> + * <constructor-arg type="java.util.logging.Logger"> + * <bean class="java.util.logging.Logger"> + * <constructor-arg type="java.lang.String" value="global"/> + * </bean> + * </constructor-arg> + * </bean> + * </property> + * ... + * </pre> + * or + * <pre name="code" class="xml"> + * ... + * <property name="gridLogger"> + * <bean class="org.gridgain.grid.logger.java.GridJavaLogger"/> + * </property> + * ... + * </pre> + * And the same configuration if you'd like to configure GridGain in your code: + * <pre name="code" class="java"> + * GridConfiguration cfg = new GridConfiguration(); + * ... + * GridLogger log = new GridJavaLogger(Logger.global); + * ... + * cfg.setGridLogger(log); + * </pre> + * or which is actually the same: + * <pre name="code" class="java"> + * GridConfiguration cfg = new GridConfiguration(); + * ... + * GridLogger log = new GridJavaLogger(); + * ... + * cfg.setGridLogger(log); + * </pre> + * Please take a look at <a target=_new href="http://java.sun.com/j2se/1.4.2/docs/api20/java/util/logging/Logger.html">Logger javadoc</a> + * for additional information. + * <p> + * It's recommended to use GridGain logger injection instead of using/instantiating + * logger in your task/job code. See {@link org.apache.ignite.resources.IgniteLoggerResource} annotation about logger + * injection. + */ +public class JavaLogger implements IgniteLogger, LoggerNodeIdAware { + /** */ + private static final long serialVersionUID = 0L; + + /** */ + public static final String DFLT_CONFIG_PATH = "config/java.util.logging.properties"; + + /** */ + private static final Object mux = new Object(); + + /** */ + private static volatile boolean inited; + + /** */ + private static volatile boolean quiet0; + + /** Java Logging implementation proxy. */ + @SuppressWarnings("FieldAccessedSynchronizedAndUnsynchronized") + private Logger impl; + + /** Quiet flag. */ + private final boolean quiet; + + /** Node ID. */ + private volatile UUID nodeId; + + /** + * Creates new logger. + */ + public JavaLogger() { + this(!isConfigured()); + } + + /** + * Checks if logger is already configured within this VM or not. + * + * @return {@code True} if logger was already configured, {@code false} otherwise. + */ + public static boolean isConfigured() { + return System.getProperty("java.util.logging.config.file") != null; + } + + /** + * Reads default JUL configuration. + */ + private void defaultConfiguration() { + final URL cfgUrl = U.resolveGridGainUrl(DFLT_CONFIG_PATH); + + if (cfgUrl == null) { + error("Failed to resolve default logging config file: " + DFLT_CONFIG_PATH); + + return; + } + + try (InputStream in = cfgUrl.openStream()) { + LogManager.getLogManager().readConfiguration(in); + } + catch (IOException e) { + error("Failed to read logging configuration: " + cfgUrl, e); + } + } + + /** + * Creates new logger. + * + * @param init If {@code true}, then a default console appender will be created. + * If {@code false}, then no implicit initialization will take place, + * and java logger should be configured prior to calling this constructor. + */ + public JavaLogger(boolean init) { + impl = Logger.getLogger(""); + + if (init) { + // Implementation has already been inited, passing NULL. + configure(null); + + quiet = quiet0; + } + else + quiet = true; + } + + /** + * Creates new logger with given implementation. + * + * @param impl Java Logging implementation to use. + */ + public JavaLogger(final Logger impl) { + assert impl != null; + + configure(impl); + + quiet = quiet0; + } + + /** {@inheritDoc} */ + @Override public IgniteLogger getLogger(Object ctgr) { + return new JavaLogger(ctgr == null ? Logger.getLogger("") : Logger.getLogger( + ctgr instanceof Class ? ((Class)ctgr).getName() : String.valueOf(ctgr))); + } + + /** + * Configures handlers when needed. + * + * @param initImpl Optional log implementation. + */ + private void configure(@Nullable Logger initImpl) { + if (initImpl != null) + impl = initImpl; + + if (inited) + return; + + synchronized (mux) { + if (inited) + return; + + if (isConfigured()) { + boolean consoleHndFound = findHandler(impl, ConsoleHandler.class) != null; + + // User configured console appender, thus log is not quiet. + quiet0 = !consoleHndFound; + inited = true; + + return; + } + + defaultConfiguration(); + + boolean quiet = Boolean.valueOf(System.getProperty(IGNITE_QUIET, "true")); + boolean useConsoleAppender = Boolean.valueOf(System.getProperty(IGNITE_CONSOLE_APPENDER, "true")); + + if (useConsoleAppender) { + ConsoleHandler consoleHnd = findHandler(impl, ConsoleHandler.class); + + if (consoleHnd != null) + consoleHnd.setLevel(quiet ? SEVERE : INFO); + else + System.err.println("Console logging handler is not configured."); + } + else { + Handler[] handlers = Logger.getLogger("").getHandlers(); + + if (!F.isEmpty(handlers)) { + for (Handler h : handlers) { + if (h instanceof ConsoleHandler) + impl.removeHandler(h); + } + } + } + + quiet0 = quiet; + inited = true; + } + } + + /** {@inheritDoc} */ + @Override public void trace(String msg) { + if (!impl.isLoggable(FINEST)) + warning("Logging at TRACE level without checking if TRACE level is enabled: " + msg); + + impl.finest(msg); + } + + /** {@inheritDoc} */ + @Override public void debug(String msg) { + if (!impl.isLoggable(FINE)) + warning("Logging at DEBUG level without checking if DEBUG level is enabled: " + msg); + + impl.fine(msg); + } + + /** {@inheritDoc} */ + @Override public void info(String msg) { + if (!impl.isLoggable(INFO)) + warning("Logging at INFO level without checking if INFO level is enabled: " + msg); + + impl.info(msg); + } + + /** {@inheritDoc} */ + @Override public void warning(String msg) { + impl.warning(msg); + } + + /** {@inheritDoc} */ + @Override public void warning(String msg, @Nullable Throwable e) { + impl.log(WARNING, msg, e); + } + + /** {@inheritDoc} */ + @Override public void error(String msg) { + impl.severe(msg); + } + + /** {@inheritDoc} */ + @Override public boolean isQuiet() { + return quiet; + } + + /** {@inheritDoc} */ + @Override public void error(String msg, @Nullable Throwable e) { + impl.log(SEVERE, msg, e); + } + + /** {@inheritDoc} */ + @Override public boolean isTraceEnabled() { + return impl.isLoggable(FINEST); + } + + /** {@inheritDoc} */ + @Override public boolean isDebugEnabled() { + return impl.isLoggable(FINE); + } + + /** {@inheritDoc} */ + @Override public boolean isInfoEnabled() { + return impl.isLoggable(INFO); + } + + /** {@inheritDoc} */ + @Nullable @Override public String fileName() { + JavaLoggerFileHandler gridFileHnd = findHandler(impl, JavaLoggerFileHandler.class); + + if (gridFileHnd != null) + return gridFileHnd.fileName(); + + FileHandler fileHnd = findHandler(impl, FileHandler.class); + + return fileName(fileHnd); + } + + /** + * @param fileHnd File handler. + * @return Current log file or {@code null} if it can not be retrieved from file handler. + */ + @Nullable static String fileName(FileHandler fileHnd) { + if (fileHnd == null) + return null; + + try { + File[] logFiles = U.field(fileHnd, "files"); + + return logFiles[0].getAbsolutePath(); + } + catch (Exception ignored) { + return null; + } + } + + /** {@inheritDoc} */ + @Override public void setNodeId(UUID nodeId) { + A.notNull(nodeId, "nodeId"); + + if (this.nodeId != null) + return; + + synchronized (mux) { + // Double check. + if (this.nodeId != null) + return; + + this.nodeId = nodeId; + } + + JavaLoggerFileHandler fileHnd = findHandler(impl, JavaLoggerFileHandler.class); + + if (fileHnd == null) + return; + + try { + fileHnd.nodeId(nodeId); + } + catch (IgniteCheckedException | IOException e) { + throw new RuntimeException("Failed to enable file handler.", e); + } + } + + /** {@inheritDoc} */ + @Override public UUID getNodeId() { + return nodeId; + } + + /** + * Returns first found handler of specified class type or {@code null} if that handler isn't configured. + * + * @param log Logger. + * @param cls Class. + * @param <T> Class type. + * @return First found handler of specified class type or {@code null} if that handler isn't configured. + */ + @SuppressWarnings("unchecked") + private static <T> T findHandler(Logger log, Class<T> cls) { + while (log != null) { + for (Handler hnd : log.getHandlers()) { + if (cls.isInstance(hnd)) + return (T)hnd; + } + + log = log.getParent(); + } + + return null; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5fa6d5cb/modules/core/src/main/java/org/apache/ignite/logger/java/JavaLoggerFileHandler.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/logger/java/JavaLoggerFileHandler.java b/modules/core/src/main/java/org/apache/ignite/logger/java/JavaLoggerFileHandler.java new file mode 100644 index 0000000..830a51e --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/logger/java/JavaLoggerFileHandler.java @@ -0,0 +1,190 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.logger.java; + +import org.apache.ignite.*; +import org.apache.ignite.internal.util.typedef.*; +import org.apache.ignite.internal.util.typedef.internal.*; +import org.jetbrains.annotations.*; + +import java.io.*; +import java.util.*; +import java.util.logging.*; + +/** + * File logging handler which skips all the messages until node ID is set. + */ +public final class JavaLoggerFileHandler extends StreamHandler { + /** Log manager. */ + private static final LogManager manager = LogManager.getLogManager(); + + /** Handler delegate. */ + private volatile FileHandler delegate; + + /** {@inheritDoc} */ + @SuppressWarnings("NonSynchronizedMethodOverridesSynchronizedMethod") + @Override public void publish(LogRecord record) { + FileHandler delegate0 = delegate; + + if (delegate0 != null) + delegate0.publish(record); + } + + /** {@inheritDoc} */ + @SuppressWarnings("NonSynchronizedMethodOverridesSynchronizedMethod") + @Override public void flush() { + FileHandler delegate0 = delegate; + + if (delegate0 != null) + delegate0.flush(); + } + + /** {@inheritDoc} */ + @SuppressWarnings("NonSynchronizedMethodOverridesSynchronizedMethod") + @Override public void close() throws SecurityException { + FileHandler delegate0 = delegate; + + if (delegate0 != null) + delegate0.close(); + } + + /** {@inheritDoc} */ + @SuppressWarnings("NonSynchronizedMethodOverridesSynchronizedMethod") + @Override public boolean isLoggable(LogRecord record) { + FileHandler delegate0 = delegate; + + return delegate0 != null && delegate0.isLoggable(record); + } + + /** + * Sets Node id and instantiates {@link FileHandler} delegate. + * + * @param nodeId Node id. + */ + public void nodeId(UUID nodeId) throws IgniteCheckedException, IOException { + if (delegate != null) + return; + + String clsName = getClass().getName(); + + String ptrn = manager.getProperty(clsName + ".pattern"); + + if (ptrn == null) + ptrn = "ignite-%{id8}.%g.log"; + + ptrn = new File(logDirectory(), ptrn.replace("%{id8}", U.id8(nodeId))).getAbsolutePath(); + + int limit = getIntProperty(clsName + ".limit", 0); + + if (limit < 0) + limit = 0; + + int cnt = getIntProperty(clsName + ".count", 1); + + if (cnt <= 0) + cnt = 1; + + boolean append = getBooleanProperty(clsName + ".append", false); + + FileHandler delegate0; + + synchronized (this) { + if (delegate != null) + return; + + delegate = delegate0 = new FileHandler(ptrn, limit, cnt, append); + } + + delegate0.setLevel(getLevel()); + delegate0.setFormatter(getFormatter()); + delegate0.setEncoding(getEncoding()); + delegate0.setFilter(getFilter()); + delegate0.setErrorManager(getErrorManager()); + } + + /** + * Returns current log file. + * + * @return Pattern or {@code null} if node id has not been set yet. + */ + @Nullable public String fileName() { + return JavaLogger.fileName(delegate); + } + + /** + * Resolves logging directory. + * + * @return Logging directory. + */ + private static File logDirectory() throws IgniteCheckedException { + return !F.isEmpty(U.IGNITE_LOG_DIR) ? new File(U.IGNITE_LOG_DIR) : U.resolveWorkDirectory("log", false); + } + + /** + * Returns integer property from logging configuration. + * + * @param name Property name. + * @param dfltVal Default value. + * @return Parsed property value if it is set and valid or default value otherwise. + */ + private int getIntProperty(String name, int dfltVal) { + String val = manager.getProperty(name); + + if (val == null) + return dfltVal; + + try { + return Integer.parseInt(val.trim()); + } + catch (Exception ex) { + ex.printStackTrace(); + + return dfltVal; + } + } + + /** + * Returns boolean property from logging configuration. + * + * @param name Property name. + * @param dfltVal Default value. + * @return Parsed property value if it is set and valid or default value otherwise. + */ + @SuppressWarnings("SimplifiableIfStatement") + private boolean getBooleanProperty(String name, boolean dfltVal) { + String val = manager.getProperty(name); + + if (val == null) + return dfltVal; + + val = val.toLowerCase(); + + if ("true".equals(val) || "1".equals(val)) + return true; + + if ("false".equals(val) || "0".equals(val)) + return false; + + return dfltVal; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(JavaLoggerFileHandler.class, this); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5fa6d5cb/modules/core/src/main/java/org/apache/ignite/logger/java/JavaLoggerFormatter.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/logger/java/JavaLoggerFormatter.java b/modules/core/src/main/java/org/apache/ignite/logger/java/JavaLoggerFormatter.java new file mode 100644 index 0000000..5621559 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/logger/java/JavaLoggerFormatter.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.logger.java; + +import org.apache.ignite.internal.util.typedef.internal.*; + +import java.io.*; +import java.text.*; +import java.util.*; +import java.util.logging.Formatter; +import java.util.logging.*; + +/** + * Formatter for JUL logger. + */ +public class JavaLoggerFormatter extends Formatter { + /** Name for anonymous loggers. */ + public static final String ANONYMOUS_LOGGER_NAME = "UNKNOWN"; + + /** */ + private static final ThreadLocal<SimpleDateFormat> DATE_FORMATTER = new ThreadLocal<SimpleDateFormat>() { + /** {@inheritDoc} */ + @Override protected SimpleDateFormat initialValue() { + return new SimpleDateFormat("HH:mm:ss,SSS"); + } + }; + + /** {@inheritDoc} */ + @SuppressWarnings("ThrowableResultOfMethodCallIgnored") + @Override public String format(LogRecord record) { + String threadName = Thread.currentThread().getName(); + + String logName = record.getLoggerName(); + + if (logName == null) + logName = ANONYMOUS_LOGGER_NAME; + else if (logName.contains(".")) + logName = logName.substring(logName.lastIndexOf('.') + 1); + + String ex = null; + + if (record.getThrown() != null) { + StringWriter sw = new StringWriter(); + + record.getThrown().printStackTrace(new PrintWriter(sw)); + + String stackTrace = sw.toString(); + + ex = "\n" + stackTrace; + } + + return "[" + DATE_FORMATTER.get().format(new Date(record.getMillis())) + "][" + + record.getLevel() + "][" + + threadName + "][" + + logName + "] " + + record.getMessage() + + (ex == null ? "\n" : ex); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(JavaLoggerFormatter.class, this); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5fa6d5cb/modules/core/src/main/java/org/apache/ignite/startup/BasicWarmupClosure.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/startup/BasicWarmupClosure.java b/modules/core/src/main/java/org/apache/ignite/startup/BasicWarmupClosure.java index 9847089..21f421e 100644 --- a/modules/core/src/main/java/org/apache/ignite/startup/BasicWarmupClosure.java +++ b/modules/core/src/main/java/org/apache/ignite/startup/BasicWarmupClosure.java @@ -209,9 +209,9 @@ public class BasicWarmupClosure implements IgniteInClosure<IgniteConfiguration> cfg0.setDiscoverySpi(discoSpi); - cfg0.setGridLogger(new IgniteNullLogger()); + cfg0.setGridLogger(new NullLogger()); - cfg0.setGridName("gridgain-warmup-grid-" + i); + cfg0.setGridName("ignite-warmup-grid-" + i); ignites.add(Ignition.start(cfg0)); } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5fa6d5cb/modules/core/src/test/java/org/apache/ignite/internal/GridLifecycleAwareSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridLifecycleAwareSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/GridLifecycleAwareSelfTest.java index 3c99eb4..96aa496 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/GridLifecycleAwareSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/GridLifecycleAwareSelfTest.java @@ -125,7 +125,7 @@ public class GridLifecycleAwareSelfTest extends GridAbstractLifecycleAwareSelfTe /** */ - private static class TestLogger extends IgniteJavaLogger implements LifecycleAware { + private static class TestLogger extends JavaLogger implements LifecycleAware { /** */ private final TestLifecycleAware lifecycleAware = new TestLifecycleAware(null);