Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- Added logger for log4j2

- Added log4j (2 JARs)
- JIRA: https://issues.jboss.org/browse/JGRP-1585
- Defined correct lib/* inclusion for JARs in ./lib dir
- Added config file for JUL logging
- log4j2.xml: added follow=true (to tweak stdout/stderr)
- JUnitXMLReporter: deleting old test directory before running new test
- Using String.format() instead of MessageFormat.format()
- Added vararg methods to Log
- Implementation of log impls (+vararg methods)
- Added support for log4j2 to LogFactory (prefers log4j2 over log4j over JUL)
- Set the dest in UNICAST_MessagesToSelfTest: before it was null, so we didn't really test unicast messages !
- Using runtest in build.xml
- Fixed incorrect path for byteman tests
- Documentation for logging
  • Loading branch information...
commit 9f2bb99efd0ba4d45feec2b1572a81b96c18bfb3 1 parent 49ba286
@belaban authored
Showing with 644 additions and 243 deletions.
  1. +12 −7 bin/jgroups.sh
  2. +18 −35 build.xml
  3. +17 −17 conf/jg-messages.properties
  4. +17 −17 conf/jg-messages_de.properties
  5. +15 −0 conf/log4j2.xml
  6. +55 −0 conf/logging.properties
  7. +66 −0 doc/manual/en/modules/installation.xml
  8. +14 −0 lib/licenses/thirdparty-licenses.xml
  9. BIN  lib/log4j-api-2.0-beta4.jar
  10. BIN  lib/log4j-core-2.0-beta4.jar
  11. +1 −1  src/org/jgroups/blocks/TCPConnectionMap.java
  12. +3 −19 src/org/jgroups/conf/ClassConfigurator.java
  13. +1 −1  src/org/jgroups/conf/ConfiguratorFactory.java
  14. +1 −1  src/org/jgroups/conf/XmlConfigurator.java
  15. +4 −4 src/org/jgroups/jmx/ResourceDMBean.java
  16. +58 −13 src/org/jgroups/logging/JDKLogImpl.java
  17. +11 −0 src/org/jgroups/logging/Log.java
  18. +152 −0 src/org/jgroups/logging/Log4J2LogImpl.java
  19. +59 −13 src/org/jgroups/logging/Log4JLogImpl.java
  20. +50 −23 src/org/jgroups/logging/LogFactory.java
  21. +0 −2  src/org/jgroups/protocols/BPING.java
  22. +0 −1  src/org/jgroups/protocols/COUNTER.java
  23. +0 −2  src/org/jgroups/protocols/RSVP.java
  24. +0 −1  src/org/jgroups/protocols/STOMP.java
  25. +7 −3 src/org/jgroups/protocols/TP.java
  26. +20 −22 src/org/jgroups/protocols/UDP.java
  27. +5 −5 src/org/jgroups/protocols/UNICAST.java
  28. +2 −6 src/org/jgroups/protocols/UNICAST3.java
  29. +1 −1  src/org/jgroups/protocols/pbcast/GMS.java
  30. +1 −1  src/org/jgroups/protocols/pbcast/NAKACK.java
  31. +2 −2 src/org/jgroups/protocols/pbcast/NAKACK2.java
  32. +0 −2  src/org/jgroups/protocols/tom/TOA.java
  33. +7 −7 src/org/jgroups/stack/Configurator.java
  34. +1 −1  src/org/jgroups/stack/IpAddress.java
  35. +2 −4 src/org/jgroups/util/SuppressLog.java
  36. +1 −11 src/org/jgroups/util/Util.java
  37. +32 −6 tests/junit-functional/org/jgroups/protocols/UNICAST_MessagesToSelfTest.java
  38. +2 −7 tests/junit-functional/org/jgroups/tests/LargeMergeTest.java
  39. +7 −8 tests/util/org/jgroups/util/JUnitXMLReporter.java
View
19 bin/jgroups.sh
@@ -13,17 +13,22 @@ if [ ! -d $LIB ]; then
LIB=$JG
fi;
-for i in $LIB/*.jar
-do
- CP=$CP:$i
-done
+CP=$CP:$LIB/*
if [ -f $HOME/log4j.properties ]; then
LOG="-Dlog4j.configuration=file:$HOME/log4j.properties"
fi;
-JG_FLAGS="-Dresolve.dns=false -Djgroups.bind_addr=$IP_ADDR -Djboss.tcpping.initial_hosts=$IP_ADDR[7800]"
-JG_FLAGS="$JG_FLAGS -Djava.net.preferIPv4Stack=true -Djgroups.timer.num_threads=4"
+if [ -f $HOME/log4j2.xml ]; then
+ LOG="$LOG -Dlog4j.configurationFile=$HOME/log4j2.xml"
+fi;
+
+if [ -f $HOME/logging.properties ]; then
+ LOG="$LOG -Djava.util.logging.config.file=$HOME/logging.properties"
+fi;
+
+JG_FLAGS="-Djgroups.bind_addr=$IP_ADDR -Djboss.tcpping.initial_hosts=$IP_ADDR[7800]"
+JG_FLAGS="$JG_FLAGS -Djava.net.preferIPv4Stack=true"
FLAGS="-server -Xmx600M -Xms600M"
FLAGS="$FLAGS -XX:CompileThreshold=10000 -XX:+AggressiveHeap -XX:ThreadStackSize=64K -XX:SurvivorRatio=8"
FLAGS="$FLAGS -XX:TargetSurvivorRatio=90 -XX:MaxTenuringThreshold=31"
@@ -42,5 +47,5 @@ EXPERIMENTAL="$EXPERIMENTAL -XX:+EliminateLocks -XX:+UseBiasedLocking"
#DEBUG="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5000"
-java -classpath $CP $DEBUG $LOG $JG_FLAGS $FLAGS $EXPERIMENTAL $JMX $*
+java -cp $CP $DEBUG $LOG $JG_FLAGS $FLAGS $EXPERIMENTAL $JMX $*
View
53 build.xml
@@ -388,48 +388,29 @@
<target name="functional" depends="postcompile">
<mkdir dir="${tmp.dir}/test-results/xml/functional"/>
- <testng classpathref="jg.classpath"
- usedefaultlisteners="false"
- outputdir="${tmp.dir}/test-results/xml"
- listeners="org.jgroups.util.JUnitXMLReporter"
- threadcount="10"
- parallel="methods"
- >
- <jvmarg value="-Djava.net.preferIPv4Stack=${java.net.preferIPv4Stack}"/>
- <jvmarg value="-Djava.net.preferIPv6Addresses=${java.net.preferIPv6Addresses}"/>
- <xmlfileset dir="${testng.conf.dir}" includes="functional.xml"/>
- </testng>
+ <runtest testname.ext="functional"
+ threadcount="10"
+ parallel="methods"
+ testng.xmlfile="functional.xml"/>
</target>
+
<target name="byteman" depends="postcompile">
<mkdir dir="${tmp.dir}/test-results/xml/byteman"/>
- <testng classpathref="jg.classpath.byteman"
- usedefaultlisteners="false"
- outputdir="${tmp.dir}/test-results/xml"
- listeners="org.jgroups.util.JUnitXMLReporter"
- threadcount="1"
- parallel="false"
- >
- <jvmarg value="-Djava.net.preferIPv4Stack=${java.net.preferIPv4Stack}"/>
- <jvmarg value="-Djava.net.preferIPv6Addresses=${java.net.preferIPv6Addresses}"/>
- <jvmarg value="-Djgroups.bind_addr=${jgroups.bind_addr}"/>
- <xmlfileset dir="${testng.conf.dir}" includes="byteman.xml"/>
- </testng>
+ <runtest classpath="jg.classpath.byteman"
+ testname.ext="byteman"
+ threadcount="1"
+ parallel="false"
+ testng.xmlfile="byteman.xml"/>
</target>
+
<target name="time-sensitive" depends="postcompile">
<mkdir dir="${tmp.dir}/test-results/xml/time-sensitive"/>
- <testng classpathref="jg.classpath"
- usedefaultlisteners="false"
- outputdir="${tmp.dir}/test-results/xml"
- listeners="org.jgroups.util.JUnitXMLReporter"
- threadcount="1"
- parallel="methods"
- >
- <jvmarg value="-Djava.net.preferIPv4Stack=${java.net.preferIPv4Stack}"/>
- <jvmarg value="-Djava.net.preferIPv6Addresses=${java.net.preferIPv6Addresses}"/>
- <xmlfileset dir="${testng.conf.dir}" includes="time-sensitive.xml"/>
- </testng>
+ <runtest testname.ext="sensitive"
+ threadcount="1"
+ parallel="methods"
+ testng.xmlfile="time-sensitive.xml"/>
</target>
<target name="stack-independent" depends="postcompile">
@@ -538,6 +519,7 @@
<macrodef name="runtest" description="Runs a configuration-dependent test suite">
+ <attribute name="classpath" default="jg.classpath"/>
<attribute name="outputdir" default="${tmp.dir}/test-results/xml"/>
<attribute name="parallel" default="methods"/>
<attribute name="testname.ext" default="udp"/>
@@ -549,7 +531,7 @@
<attribute name="tcp.recv.buf.size" default="200000"/>
<attribute name="tcp.send.buf.size" default="64000"/>
<sequential>
- <testng classpathref="jg.classpath"
+ <testng classpathref="@{classpath}"
usedefaultlisteners="false"
outputdir="@{outputdir}"
listeners="org.jgroups.util.JUnitXMLReporter"
@@ -568,6 +550,7 @@
<jvmarg value="-Djgroups.tunnel.gossip_router_hosts=${jgroups.tunnel.gossip_router_hosts}"/>
<jvmarg value="-Dtests.tmp.dir=${tmp.dir}"/>
<jvmarg value="-Dlog4j.configuration=file:${conf.dir}/log4j.properties"/>
+ <jvmarg value="-Dlog4j.configurationFile=${conf.dir}/log4j2.xml"/>
<jvmarg value="-Djava.net.preferIPv4Stack=${java.net.preferIPv4Stack}"/>
<jvmarg value="-Djava.net.preferIPv6Addresses=${java.net.preferIPv6Addresses}"/>
<jvmarg value="-Xms400M"/>
View
34 conf/jg-messages.properties
@@ -1,17 +1,17 @@
-ConfigurationError = [JGRP00001] configuration error: the following properties in {0} are not recognized: {1}
-ProtocolLoadError = [JGRP00002] unable to load protocol {0} (either with relative - {0} - or absolute - {1} - class name)
-FileNotFound = [JGRP00003] file \"{0}\" not found
-ParseError = [JGRP00004] parsing failure; the XML document is not correct: {0}
-ProtocolCreateError = [JGRP00005] failure creating protocol {0}: {1}
-AcceptError = [JGRP00006] failed accepting connection from peer: {0}
-AttrReadFailure = [JGRP00007] failed reading value of attribute {0}: {1}
-MissingAttribute = [JGRP00008] did not find attribute with name {0}
-AttrWriteFailure = [JGRP00009] failed writing to attribute {0}: {1}
-VersionMismatch = [JGRP00010] packet from {0} has different version ({1}) than ours ({2}); packet is discarded
-MsgDroppedNak = [JGRP00011] {0}: dropped message {1} from non-member {2} (view={3})
-MsgDroppedDiffCluster = [JGRP00012] discarded message from different cluster {0} (our cluster is {1}). Sender was {2}
-BatchDroppedDiffCluster = [JGRP00013] discarded message batch from different cluster {0} (our cluster is {1}). Sender was {2}
-SuppressMsg = (received {0} identical messages from {1} in the last {2} ms)
-Deprecated = [JGRP00014] {0} has been deprecated: {1}
-IncorrectBufferSize = [JGRP00015] the {0} buffer of socket {1} was set to {2}, but the OS only allocated {3}. \
- This might lead to performance problems. Please set your max {4} buffer in the OS correctly (e.g. {5} on Linux)
+ConfigurationError = [JGRP00001] configuration error: the following properties in %s are not recognized: %s
+ProtocolLoadError = [JGRP00002] unable to load protocol %1$s (either with relative - %1$s - or absolute - %2$s - class name)
+FileNotFound = [JGRP00003] file \"%s\" not found
+ParseError = [JGRP00004] parsing failure; the XML document is not correct: %s
+ProtocolCreateError = [JGRP00005] failure creating protocol %s: %s
+AcceptError = [JGRP00006] failed accepting connection from peer: %s
+AttrReadFailure = [JGRP00007] failed reading value of attribute %s: %s
+MissingAttribute = [JGRP00008] did not find attribute with name %s
+AttrWriteFailure = [JGRP00009] failed writing to attribute %s: %s
+VersionMismatch = [JGRP00010] packet from %s has different version (%s) than ours (%s); packet is discarded
+MsgDroppedNak = [JGRP00011] %s: dropped message %s from non-member %s (view=%s)
+MsgDroppedDiffCluster = [JGRP00012] discarded message from different cluster %s (our cluster is %s). Sender was %s
+BatchDroppedDiffCluster = [JGRP00013] discarded message batch from different cluster %s (our cluster is %s). Sender was %s
+SuppressMsg = (received %d identical messages from %s in the last %d ms)
+Deprecated = [JGRP00014] %s has been deprecated: %s
+IncorrectBufferSize = [JGRP00015] the %s buffer of socket %s was set to %s, but the OS only allocated %s. \
+ This might lead to performance problems. Please set your max %s buffer in the OS correctly (e.g. %s on Linux)
View
34 conf/jg-messages_de.properties
@@ -1,17 +1,17 @@
-ConfigurationError = [JGRP00001] Konfigurationsfehler: die folgenden Parameter in {0} sind nicht erlaubt: {1}
-ProtocolLoadError = [JGRP00002] Fehler beim Laden des Protokolls {0} (sowohl mit relativem - {0} - als auch absolutem - {1} - Pfadnamen)
-FileNotFound = [JGRP00003] Datei \"{0}\" nicht gefunden
-ParseError = [JGRP00004] Fehler beim Parsen von XML; das Dokument ist nicht korrekt: {0}
-ProtocolCreateError = [JGRP00005] Protokoll {0} konnte nicht instantiiert werden: {1}
-AcceptError = [JGRP00006] Verbindung vom Peer konnte nicht hergestellt werden: {0}
-AttrReadFailure = [JGRP00007] Attribut {0} konnte nicht gelesen werden: {1}
-MissingAttribute = [JGRP00008] Attribut {0} wurde nicht gefunden
-AttrWriteFailure = [JGRP00009] Attribut {0} konnte nicht geschrieben werden: {1}
-VersionMismatch = [JGRP00010] Nachricht von {0} hat eine andere Version ({1}) als unsere ({2}); Nachricht wird verworfen
-MsgDroppedNak = [JGRP00011] {0}: Nachricht {1} von Nicht-Mitglied {2} wurde verworfen (View={3})
-MsgDroppedDiffCluster = [JGRP00012] Nachricht von Cluster {0} wurde verworfen (unser Cluster ist {1}). Der Sender war {2}
-BatchDroppedDiffCluster = [JGRP00013] Nachrichten-Batch von Cluster {0} wurde verworfen (unser Cluster ist {1}). Der Sender war {2}
-SuppressMsg = ({0} identische Nachrichten erhalten von {1} in den letzten {2} ms)
-Deprecated = [JGRP00014] {0} wird nicht mehr unterstuetzt: {1}
-IncorrectBufferSize = [JGRP00015] Der {0} Puffer des Sockets {1} wurde auf {2} gesetzt, aber das Betriebssystem stellt nur {3} zur Verfuegung. \
- Dies koennte zu Performanzproblemen fuehren. Bitte setzen Sie den max {4} Puffer im Betriebssystem korrekt (z.B. {5} unter Linux)
+ConfigurationError = [JGRP00001] Konfigurationsfehler: die folgenden Parameter in %s sind nicht erlaubt: %s
+ProtocolLoadError = [JGRP00002] Fehler beim Laden des Protokolls %1$s (sowohl mit relativem - %1$s - als auch absolutem - %2$s - Pfadnamen)
+FileNotFound = [JGRP00003] Datei \"%s\" nicht gefunden
+ParseError = [JGRP00004] Fehler beim Parsen von XML; das Dokument ist nicht korrekt: %s
+ProtocolCreateError = [JGRP00005] Protokoll %s konnte nicht instantiiert werden: %s
+AcceptError = [JGRP00006] Verbindung vom Peer konnte nicht hergestellt werden: %s
+AttrReadFailure = [JGRP00007] Attribut %s konnte nicht gelesen werden: %s
+MissingAttribute = [JGRP00008] Attribut %s wurde nicht gefunden
+AttrWriteFailure = [JGRP00009] Attribut %s konnte nicht geschrieben werden: %s
+VersionMismatch = [JGRP00010] Nachricht von %s hat eine andere Version (%s) als unsere (%s); Nachricht wird verworfen
+MsgDroppedNak = [JGRP00011] %s: Nachricht %s von Nicht-Mitglied %s wurde verworfen (View=%s)
+MsgDroppedDiffCluster = [JGRP00012] Nachricht von Cluster %s wurde verworfen (unser Cluster ist %s). Der Sender war %s
+BatchDroppedDiffCluster = [JGRP00013] Nachrichten-Batch von Cluster %s wurde verworfen (unser Cluster ist %s). Der Sender war %s
+SuppressMsg = (%d identische Nachrichten erhalten von %s in den letzten %d ms)
+Deprecated = [JGRP00014] %s wird nicht mehr unterstuetzt: %s
+IncorrectBufferSize = [JGRP00015] Der %s Puffer des Sockets %s wurde auf %s gesetzt, aber das Betriebssystem stellt nur %s zur Verfuegung. \
+ Dies koennte zu Performanzproblemen fuehren. Bitte setzen Sie den max %s Puffer im Betriebssystem korrekt (z.B. %s unter Linux)
View
15 conf/log4j2.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+ <appenders>
+ <Console name="STDOUT" target="SYSTEM_OUT" follow="true">
+ <!--PatternLayout pattern="%-7d{HH:mm:ss,SSS} [%p] %c: %m%n"/-->
+ <PatternLayout pattern="%r [%p] %c{1}: %m%n"/>
+ </Console>
+ </appenders>
+ <loggers>
+ <root level="warn">
+ <appender-ref ref="STDOUT"/>
+ </root>
+ <logger name="org.jgroups" level="warn"/>
+ </loggers>
+</configuration>
View
55 conf/logging.properties
@@ -0,0 +1,55 @@
+############################################################
+# Default Logging Configuration File
+#
+# You can use a different file by specifying a filename
+# with the java.util.logging.config.file system property.
+# For example java -Djava.util.logging.config.file=myfile
+############################################################
+
+############################################################
+# Global properties
+############################################################
+
+# "handlers" specifies a comma separated list of log Handler
+# classes. These handlers will be installed during VM startup.
+# Note that these classes must be on the system classpath.
+# By default we only configure a ConsoleHandler, which will only
+# show messages at the INFO and above levels.
+handlers= java.util.logging.ConsoleHandler
+
+# To also add the FileHandler, use the following line instead.
+#handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler
+
+# Default global logging level.
+# This specifies which kinds of events are logged across
+# all loggers. For any given facility this global level
+# can be overriden by a facility specific level
+# Note that the ConsoleHandler also has a separate level
+# setting to limit messages printed to the console.
+.level=WARNING
+
+############################################################
+# Handler specific properties.
+# Describes specific configuration info for Handlers.
+############################################################
+
+# default file output is in user's home directory.
+java.util.logging.FileHandler.pattern = %h/java%u.log
+java.util.logging.FileHandler.limit = 50000
+java.util.logging.FileHandler.count = 1
+java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter
+
+# Limit the message that are printed on the console to INFO and above.
+java.util.logging.ConsoleHandler.level = FINEST
+java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
+
+
+############################################################
+# Facility specific properties.
+# Provides extra control for each logger.
+############################################################
+
+# For example, set the com.xyz.foo logger to only log SEVERE
+# messages:
+org.jgroups = FINEST
+org.jgroups.handlers= java.util.logging.ConsoleHandler
View
66 doc/manual/en/modules/installation.xml
@@ -33,6 +33,11 @@
unittests, then xalan.jar needs to be in the CLASSPATH (also
available in the lib directory)
</listitem>
+ <listitem>
+ Logging: by default, JGroups tries to use log4j2. If the classes are not found on the classpath, it
+ resorts to log4j, and if still not found, it falls back to the java.util.logging logger.
+ See <xref linkend="Logging"/> for details on log configuration.
+ </listitem>
</itemizedlist>
</section>
@@ -169,6 +174,67 @@
</orderedlist>
</section>
+ <section id="Logging">
+ <title>Logging</title>
+ <para>
+ JGroups has no runtime dependencies; all that's needed to use it is to have jgroups.jar on the classpath.
+ For logging, this means the JVM's logging (java.util.logging) is used.
+ </para>
+ <para>
+ However, JGroups can use any other logging framework. By default, log4j and log4j2 are supported if the
+ corresponding JARs are found on the classpath.
+ </para>
+
+ <section id="log4j2">
+ <title>log4j2</title>
+ <para>
+ To use (<ulink url="http://logging.apache.org/log4j/2.x/manual/index.html">log4j2</ulink>), the
+ API and CORE JARs have to be found on the classpath. There's an XML configuration for log4j2 in the
+ conf dir, which can be used e.g. via -Dlog4j.configurationFile=$JGROUPS/conf/log4j2.xml.
+ </para>
+ <para>
+ log4j2 is currently the preferred logging library used by JGroups, and will be used even if the log4j
+ JAR is also present on the classpath.
+ </para>
+ </section>
+ <section id="log4j">
+ <title>log4j</title>
+ <para>
+ To use (<ulink url="http://logging.apache.org/log4j/1.2">log4j</ulink>), the log4j JAR has to be found
+ on the classpath. Note though that if the log4j2 API and CORE JARs are found, then log4j2 will be used,
+ so those JARs will have to be removed if log4j is to be used. There's an XML configuration for log4j in
+ the conf dir, which can be used e.g. via -Dlog4j.configuration=file:$JGROUPS/conf/log4j.properties.
+ </para>
+ </section>
+ <section id="JUL">
+ <title>JDK logging (JUL)</title>
+ <para>
+ To force use of JDK logging, even if the log4j(2) JARs are present, -Djgroups.use.jdk_logger=true
+ can be used.
+ </para>
+ </section>
+ <section id="CustomLoggers">
+ <title>Support for custom logging frameworks</title>
+ <para>
+ JGroups allows custom loggers to be used instead of the ones supported by default. To do this, interface
+ CustomLogFactory has to be implemented:
+ </para>
+ <programlisting language="Java">
+public interface CustomLogFactory {
+ Log getLog(Class clazz);
+ Log getLog(String category);
+}
+ </programlisting>
+ <para>
+ The implementation needs to return an implementation of org.jgroups.logging.Log.
+ </para>
+ <para>
+ To force using the custom log implementation, the fully qualified classname of the custom log
+ factory has to be provided via -Djgroups.logging.log_factory_class=com.foo.MyCustomLogger.
+ </para>
+ </section>
+ </section>
+
<section id="TestingTheSetup">
<title>Testing your Setup</title>
View
14 lib/licenses/thirdparty-licenses.xml
@@ -73,6 +73,20 @@
description='Java logging framework (runtime)'>
<jar name='log4j.jar' />
</module>
+ <module name='log4j2-api'
+ licenseType='apache-2.0'
+ version='2.0.0.Beta4'
+ projectHome='http://logging.apache.org/log4j/2.x/'
+ description='Java logging framework (runtime)'>
+ <jar name='log4j-api-2.0-beta4.jar' />
+ </module>
+ <module name='log4j2-core'
+ licenseType='apache-2.0'
+ version='2.0.0.Beta4'
+ projectHome='http://logging.apache.org/log4j/2.x/'
+ description='Java logging framework (runtime)'>
+ <jar name='log4j-core-2.0-beta4.jar' />
+ </module>
<module name='serializer'
licenseType='apache-2.0'
version='1.6.5'
View
BIN  lib/log4j-api-2.0-beta4.jar
Binary file not shown
View
BIN  lib/log4j-core-2.0-beta4.jar
Binary file not shown
View
2  src/org/jgroups/blocks/TCPConnectionMap.java
@@ -285,7 +285,7 @@ public void run() {
if(ex instanceof SocketException && srv_sock.isClosed() || Thread.currentThread().isInterrupted())
break;
if(log.isWarnEnabled())
- log.warn(Util.getMessage("AcceptError", ex));
+ log.warn(Util.getMessage("AcceptError"), ex);
Util.close(client_sock);
}
}
View
22 src/org/jgroups/conf/ClassConfigurator.java
@@ -3,8 +3,6 @@
import org.jgroups.Global;
-import org.jgroups.logging.Log;
-import org.jgroups.logging.LogFactory;
import org.jgroups.util.Tuple;
import org.jgroups.util.Util;
import org.w3c.dom.Document;
@@ -52,8 +50,6 @@
private static final Map<Class,Short> protocol_ids=new HashMap<Class,Short>(MAX_MAGIC_VALUE);
private static final Map<Short,Class> protocol_names=new HashMap<Short,Class>(MAX_MAGIC_VALUE);
- protected static final Log log=LogFactory.getLog(ClassConfigurator.class);
-
static {
try {
@@ -77,8 +73,6 @@ protected static void init() throws Exception {
null, null, false, MAGIC_NUMBER_FILE);
protocol_id_file=Util.getProperty(new String[]{Global.PROTOCOL_ID_FILE, "org.jgroups.conf.protocolIDFile"},
null, null, false, PROTOCOL_ID_FILE);
- if(log.isDebugEnabled()) log.debug("Using " + magic_number_file + " as magic number file and " +
- protocol_id_file + " for protocol IDs");
}
catch (SecurityException ex){
}
@@ -158,15 +152,8 @@ public static void addProtocol(short id, Class protocol) {
* @param clazzname a fully classified class name to be loaded
* @return a Class object that represents a class that implements java.io.Externalizable
*/
- public static Class get(String clazzname) {
- try {
- // return ClassConfigurator.class.getClassLoader().loadClass(clazzname);
- return Util.loadClass(clazzname, ClassConfigurator.class);
- }
- catch(Exception x) {
- if(log.isErrorEnabled()) log.error("failed loading class " + clazzname, x);
- }
- return null;
+ public static Class get(String clazzname) throws ClassNotFoundException {
+ return Util.loadClass(clazzname, ClassConfigurator.class);
}
/**
@@ -237,11 +224,8 @@ public static String printClassMap() {
InputStream stream;
stream=Util.getResourceAsStream(name, ClassConfigurator.class);
// try to load the map from file even if it is not a Resource in the class path
- if(stream == null) {
- if(log.isTraceEnabled())
- log.trace("Could not read " + name + " from the CLASSPATH, will try to read it from file");
+ if(stream == null)
stream=new FileInputStream(name);
- }
return parse(stream);
}
View
2  src/org/jgroups/conf/ConfiguratorFactory.java
@@ -209,7 +209,7 @@ static XmlConfigurator getXmlConfigurator(String properties) throws IOException
XmlConfigurator returnValue=null;
InputStream configStream=getConfigStream(properties);
if(configStream == null && properties.endsWith(".xml"))
- throw new FileNotFoundException(Util.getMessage("FileNotFound", properties));
+ throw new FileNotFoundException(String.format(Util.getMessage("FileNotFound"), properties));
if (configStream != null) {
checkJAXPAvailability();
View
2  src/org/jgroups/conf/XmlConfigurator.java
@@ -170,7 +170,7 @@ public void error(SAXParseException exception) throws SAXException {
Element configElement = document.getDocumentElement();
return parse(configElement);
} catch (Exception x) {
- throw new IOException(Util.getMessage("ParseError", x.getLocalizedMessage()));
+ throw new IOException(String.format(Util.getMessage("ParseError"), x.getLocalizedMessage()));
}
}
View
8 src/org/jgroups/jmx/ResourceDMBean.java
@@ -349,11 +349,11 @@ protected Attribute getNamedAttribute(String name) {
return new Attribute(name, entry.getter.invoke(null));
}
catch(Exception e) {
- log.warn(Util.getMessage("AttrReadFailure", name, e));
+ log.warn(Util.getMessage("AttrReadFailure"), name, e);
}
}
else {
- log.warn(Util.getMessage("MissingAttribute", name));
+ log.warn(Util.getMessage("MissingAttribute"), name);
}
return null;
}
@@ -367,11 +367,11 @@ protected boolean setNamedAttribute(Attribute attribute) {
return true;
}
catch(Throwable e) {
- log.warn(Util.getMessage("AttrWriteFailure", attribute.getName(), e));
+ log.warn(Util.getMessage("AttrWriteFailure"), attribute.getName(), e);
}
}
else {
- log.warn(Util.getMessage("MissingAttribute", attribute.getName()));
+ log.warn(Util.getMessage("MissingAttribute"), attribute.getName());
}
return false;
}
View
71 src/org/jgroups/logging/JDKLogImpl.java
@@ -1,5 +1,7 @@
package org.jgroups.logging;
+import java.util.Arrays;
+import java.util.IllegalFormatException;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -10,7 +12,7 @@
* @since 2.8
*/
public class JDKLogImpl implements Log {
- private final Logger logger;
+ protected final Logger logger;
public JDKLogImpl(String category) {
logger=Logger.getLogger(category);
@@ -48,44 +50,74 @@ public void trace(String msg) {
logger.log(Level.FINER, msg);
}
+ public void trace(String msg, Object... args) {
+ if(isTraceEnabled())
+ logger.log(Level.FINER, format(msg, args));
+ }
+
public void trace(Object msg) {
logger.log(Level.FINER, msg.toString());
}
+ public void trace(String msg, Throwable t) {
+ logger.log(Level.FINER, msg, t);
+ }
+
public void debug(String msg) {
logger.log(Level.FINE, msg);
}
+ public void debug(String msg, Object... args) {
+ if(isDebugEnabled())
+ logger.log(Level.FINE, format(msg, args));
+ }
+
+ public void debug(String msg, Throwable t) {
+ logger.log(Level.FINE, msg, t);
+ }
+
public void info(String msg) {
logger.log(Level.INFO, msg);
}
+ public void info(String msg, Object... args) {
+ if(isInfoEnabled())
+ logger.log(Level.INFO, format(msg, args));
+ }
+
public void warn(String msg) {
logger.log(Level.WARNING, msg);
}
- public void error(String msg) {
- logger.log(Level.SEVERE, msg);
+ public void warn(String msg, Object... args) {
+ if(isWarnEnabled())
+ logger.log(Level.WARNING, format(msg, args));
}
- public void fatal(String msg) {
+ public void warn(String msg, Throwable t) {
+ logger.log(Level.WARNING, msg, t);
+ }
+
+ public void error(String msg) {
logger.log(Level.SEVERE, msg);
}
- public void trace(String msg, Throwable t) {
- logger.log(Level.FINER, msg, t);
+ public void error(String format, Object... args) {
+ if(isErrorEnabled())
+ logger.log(Level.SEVERE, format(format, args));
}
- public void debug(String msg, Throwable t) {
- logger.log(Level.FINE, msg, t);
+ public void error(String msg, Throwable t) {
+ logger.log(Level.SEVERE, msg, t);
}
- public void warn(String msg, Throwable t) {
- logger.log(Level.WARNING, msg, t);
+ public void fatal(String msg) {
+ logger.log(Level.SEVERE, msg);
}
- public void error(String msg, Throwable t) {
- logger.log(Level.SEVERE, msg, t);
+ public void fatal(String msg, Object... args) {
+ if(isFatalEnabled())
+ logger.log(Level.SEVERE, format(msg, args));
}
public void fatal(String msg, Throwable t) {
@@ -103,7 +135,20 @@ public void setLevel(String level) {
logger.setLevel(new_level);
}
- private static Level strToLevel(String level) {
+ protected String format(String format, Object... args) {
+ try {
+ return String.format(format, args);
+ }
+ catch(IllegalFormatException ex) {
+ error("Illegal format string \"" + format + "\", args=" + Arrays.toString(args));
+ }
+ catch(Throwable t) {
+ error("Failure formatting string: format string=" + format + ", args=" + Arrays.toString(args));
+ }
+ return format;
+ }
+
+ protected static Level strToLevel(String level) {
if(level == null) return null;
level=level.toLowerCase().trim();
if(level.equals("fatal")) return Level.SEVERE;
View
11 src/org/jgroups/logging/Log.java
@@ -18,16 +18,27 @@
void fatal(String msg);
+ void fatal(String msg, Object ... args);
void fatal(String msg, Throwable throwable);
+
void error(String msg);
+ void error(String format, Object ... args);
void error(String msg, Throwable throwable);
+
void warn(String msg);
+ void warn(String msg, Object ... args);
void warn(String msg, Throwable throwable);
+
void info(String msg);
+ void info(String msg, Object ... args);
+
void debug(String msg);
+ void debug(String msg, Object ... args);
void debug(String msg, Throwable throwable);
+
void trace(Object msg);
void trace(String msg);
+ void trace(String msg, Object ... args);
void trace(String msg, Throwable throwable);
View
152 src/org/jgroups/logging/Log4J2LogImpl.java
@@ -0,0 +1,152 @@
+package org.jgroups.logging;
+
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.simple.SimpleLogger;
+
+/**
+ * Logger that delivers messages to a Log4J2 logger
+ *
+ * @author Bela Ban
+ * @since 3.3
+ */
+public class Log4J2LogImpl implements Log {
+ protected final Logger logger;
+
+ protected static final Level[] levels={Level.TRACE, Level.DEBUG, Level.INFO, Level.WARN, Level.ERROR, Level.FATAL};
+
+
+ public Log4J2LogImpl(String category) {
+ logger=LogManager.getFormatterLogger(category);
+ }
+
+ public Log4J2LogImpl(Class<?> category) {
+ logger = LogManager.getFormatterLogger(category);
+ }
+
+ public boolean isFatalEnabled() {return logger.isFatalEnabled();}
+ public boolean isErrorEnabled() {return logger.isErrorEnabled();}
+ public boolean isWarnEnabled() {return logger.isWarnEnabled();}
+ public boolean isInfoEnabled() {return logger.isInfoEnabled();}
+ public boolean isDebugEnabled() {return logger.isDebugEnabled();}
+ public boolean isTraceEnabled() {return logger.isTraceEnabled();}
+
+
+
+ public void trace(Object msg) {
+ logger.trace(msg);
+ }
+
+ public void trace(String msg) {
+ logger.trace(msg);
+ }
+
+ public void trace(String msg, Object... args) {
+ logger.trace(msg, args);
+ }
+
+ public void trace(String msg, Throwable throwable) {
+ logger.trace(msg, throwable);
+ }
+
+ public void debug(String msg) {
+ logger.debug(msg);
+ }
+
+ public void debug(String msg, Object... args) {
+ logger.debug(msg, args);
+ }
+
+ public void debug(String msg, Throwable throwable) {
+ logger.debug(msg, throwable);
+ }
+
+ public void info(String msg) {
+ logger.info(msg);
+ }
+
+ public void info(String msg, Object... args) {
+ logger.info(msg, args);
+ }
+
+ public void warn(String msg) {
+ logger.warn(msg);
+ }
+
+ public void warn(String msg, Object... args) {
+ logger.warn(msg, args);
+ }
+
+ public void warn(String msg, Throwable throwable) {
+ logger.warn(msg, throwable);
+ }
+
+ public void error(String msg) {
+ logger.error(msg);
+ }
+
+ public void error(String format, Object... args) {
+ logger.error(format, args);
+ }
+
+ public void error(String msg, Throwable throwable) {
+ logger.error(msg, throwable);
+ }
+
+ public void fatal(String msg) {
+ logger.fatal(msg);
+ }
+
+ public void fatal(String msg, Object... args) {
+ logger.fatal(msg, args);
+ }
+
+ public void fatal(String msg, Throwable throwable) {
+ logger.fatal(msg, throwable);
+ }
+
+
+
+
+
+
+ public String getLevel() {
+ for(Level level: levels)
+ if(logger.isEnabled(level))
+ return level.toString();
+ return "n/a";
+ }
+
+ public void setLevel(String level) {
+ Level new_level=strToLevel(level);
+ if(new_level == null)
+ return;
+ if(logger instanceof org.apache.logging.log4j.core.Logger)
+ ((org.apache.logging.log4j.core.Logger)logger).setLevel(new_level);
+ else if(logger instanceof SimpleLogger)
+ ((SimpleLogger)logger).setLevel(new_level);
+ }
+
+ private static Level strToLevel(String level) {
+ if (level == null)
+ return null;
+ level = level.toLowerCase().trim();
+ if (level.equals("fatal"))
+ return Level.FATAL;
+ if (level.equals("error"))
+ return Level.ERROR;
+ if (level.equals("warn"))
+ return Level.WARN;
+ if (level.equals("warning"))
+ return Level.WARN;
+ if (level.equals("info"))
+ return Level.INFO;
+ if (level.equals("debug"))
+ return Level.DEBUG;
+ if (level.equals("trace"))
+ return Level.TRACE;
+ return null;
+ }
+}
View
72 src/org/jgroups/logging/Log4JLogImpl.java
@@ -3,6 +3,9 @@
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
+import java.util.Arrays;
+import java.util.IllegalFormatException;
+
/**
* Logger that delivers messages to a Log4J logger
*
@@ -49,51 +52,81 @@ public boolean isTraceEnabled() {
}
public void debug(String msg) {
- logger.log(FQCN, Level.DEBUG, msg, null);
+ logger.log(FQCN,Level.DEBUG,msg,null);
+ }
+
+ public void debug(String msg, Object... args) {
+ if(isDebugEnabled())
+ debug(format(msg, args));
}
public void debug(String msg, Throwable throwable) {
- logger.log(FQCN, Level.DEBUG, msg, throwable);
+ logger.log(FQCN,Level.DEBUG,msg,throwable);
}
public void error(String msg) {
- logger.log(FQCN, Level.ERROR, msg, null);
+ logger.log(FQCN,Level.ERROR,msg,null);
+ }
+
+ public void error(String format, Object... args) {
+ if(isErrorEnabled())
+ error(format(format,args));
}
public void error(String msg, Throwable throwable) {
- logger.log(FQCN, Level.ERROR, msg, throwable);
+ logger.log(FQCN,Level.ERROR,msg,throwable);
}
public void fatal(String msg) {
- logger.log(FQCN, Level.FATAL, msg, null);
+ logger.log(FQCN,Level.FATAL,msg,null);
+ }
+
+ public void fatal(String msg, Object... args) {
+ if(isFatalEnabled())
+ fatal(format(msg, args));
}
public void fatal(String msg, Throwable throwable) {
- logger.log(FQCN, Level.FATAL, msg, throwable);
+ logger.log(FQCN,Level.FATAL,msg,throwable);
}
public void info(String msg) {
- logger.log(FQCN, Level.INFO, msg, null);
+ logger.log(FQCN,Level.INFO,msg,null);
+ }
+
+ public void info(String msg, Object... args) {
+ if(isInfoEnabled())
+ info(format(msg, args));
}
public void trace(Object msg) {
- logger.log(FQCN, Level.TRACE, msg, null);
+ logger.log(FQCN,Level.TRACE,msg,null);
}
public void trace(String msg) {
- logger.log(FQCN, Level.TRACE, msg, null);
+ logger.log(FQCN,Level.TRACE,msg,null);
+ }
+
+ public void trace(String msg, Object... args) {
+ if(isTraceEnabled())
+ trace(format(msg, args));
}
public void trace(String msg, Throwable throwable) {
- logger.log(FQCN, Level.TRACE, msg, throwable);
+ logger.log(FQCN,Level.TRACE,msg,throwable);
}
public void warn(String msg) {
- logger.log(FQCN, Level.WARN, msg, null);
+ logger.log(FQCN,Level.WARN,msg,null);
+ }
+
+ public void warn(String msg, Object... args) {
+ if(isWarnEnabled())
+ warn(format(msg, args));
}
public void warn(String msg, Throwable throwable) {
- logger.log(FQCN, Level.WARN, msg, throwable);
+ logger.log(FQCN,Level.WARN,msg,throwable);
}
public String getLevel() {
@@ -107,7 +140,20 @@ public void setLevel(String level) {
logger.setLevel(new_level);
}
- private static Level strToLevel(String level) {
+ protected String format(String format, Object... args) {
+ try {
+ return String.format(format, args);
+ }
+ catch(IllegalFormatException ex) {
+ error("Illegal format string \"" + format + "\", args=" + Arrays.toString(args));
+ }
+ catch(Throwable t) {
+ error("Failure formatting string: format string=" + format + ", args=" + Arrays.toString(args));
+ }
+ return format;
+ }
+
+ protected static Level strToLevel(String level) {
if (level == null)
return null;
level = level.toLowerCase().trim();
View
73 src/org/jgroups/logging/LogFactory.java
@@ -11,58 +11,85 @@
* @since 4.0
*/
public class LogFactory {
- public static final boolean IS_LOG4J_AVAILABLE;
+ public static final boolean IS_LOG4J2_AVAILABLE; // log4j2 is preferred over log4j
+ public static final boolean IS_LOG4J_AVAILABLE;
+ protected static final boolean USE_JDK_LOGGER;
+
+ protected static final CustomLogFactory custom_log_factory;
- private static final CustomLogFactory custom_log_factory;
static {
String customLogFactoryClass=System.getProperty(Global.CUSTOM_LOG_FACTORY);
CustomLogFactory customLogFactoryX=null;
if(customLogFactoryClass != null) {
try {
- // customLogFactoryX=(CustomLogFactory)Util.loadClass(customLogFactoryClass, null).newInstance();
customLogFactoryX=(CustomLogFactory)Class.forName(customLogFactoryClass).newInstance();
}
catch(Exception e) {
- // failed to create the custom log factory, ignore?
}
}
+
custom_log_factory=customLogFactoryX;
- boolean available;
+ USE_JDK_LOGGER=isPropertySet(Global.USE_JDK_LOGGER);
+ IS_LOG4J_AVAILABLE=isAvailable("org.apache.log4j.Logger");
+ IS_LOG4J2_AVAILABLE=isAvailable("org.apache.logging.log4j.core.Logger");
+ }
+
+
+ public static String loggerType() {
+ if(USE_JDK_LOGGER) return "jdk";
+ if(IS_LOG4J2_AVAILABLE) return "log4j2";
+ if(IS_LOG4J_AVAILABLE) return "log4j";
+ return "jdk";
+ }
+
+ protected static boolean isAvailable(String classname) {
try {
- Class.forName("org.apache.log4j.Logger");
- available=true;
+ return Class.forName(classname) != null;
}
catch(ClassNotFoundException cnfe) {
- available=false;
+ return false;
+ }
+ }
+
+ protected static boolean isPropertySet(String property_name) {
+ try {
+ return Boolean.parseBoolean(System.getProperty(property_name));
+ }
+ catch(Throwable t) {
+ return false;
}
- IS_LOG4J_AVAILABLE=available;
}
public static Log getLog(Class clazz) {
if(custom_log_factory != null)
return custom_log_factory.getLog(clazz);
- // this call is not executed frequently, so we don't need to move the check for USE_JDK_LOGGER to class init time
- final boolean use_jdk_logger=Boolean.parseBoolean(System.getProperty(Global.USE_JDK_LOGGER));
- if(IS_LOG4J_AVAILABLE && !use_jdk_logger) {
- return new Log4JLogImpl(clazz);
- }
- else {
+ if(USE_JDK_LOGGER)
return new JDKLogImpl(clazz);
- }
+
+ if(IS_LOG4J2_AVAILABLE)
+ return new Log4J2LogImpl(clazz);
+
+ if(IS_LOG4J_AVAILABLE)
+ return new Log4JLogImpl(clazz);
+
+ return new JDKLogImpl(clazz);
}
public static Log getLog(String category) {
if(custom_log_factory != null)
return custom_log_factory.getLog(category);
-
- final boolean use_jdk_logger=Boolean.parseBoolean(System.getProperty(Global.USE_JDK_LOGGER));
- if(IS_LOG4J_AVAILABLE && !use_jdk_logger) {
- return new Log4JLogImpl(category);
- }
- else {
+
+ if(USE_JDK_LOGGER)
return new JDKLogImpl(category);
- }
+
+ if(IS_LOG4J2_AVAILABLE)
+ return new Log4J2LogImpl(category);
+
+ if(IS_LOG4J_AVAILABLE)
+ return new Log4JLogImpl(category);
+
+ return new JDKLogImpl(category);
}
}
View
2  src/org/jgroups/protocols/BPING.java
@@ -3,7 +3,6 @@
import org.jgroups.Event;
import org.jgroups.Global;
import org.jgroups.Message;
-import org.jgroups.annotations.Experimental;
import org.jgroups.annotations.Property;
import org.jgroups.util.Buffer;
import org.jgroups.util.ExposedByteArrayInputStream;
@@ -24,7 +23,6 @@
* @author Bela Ban
* @since 2.12
*/
-@Experimental
public class BPING extends PING implements Runnable {
View
1  src/org/jgroups/protocols/COUNTER.java
@@ -22,7 +22,6 @@
* @author Bela Ban
* @since 3.0.0
*/
-@Experimental
@MBean(description="Protocol to maintain distributed atomic counters")
public class COUNTER extends Protocol {
View
2  src/org/jgroups/protocols/RSVP.java
@@ -1,7 +1,6 @@
package org.jgroups.protocols;
import org.jgroups.*;
-import org.jgroups.annotations.Experimental;
import org.jgroups.annotations.MBean;
import org.jgroups.annotations.ManagedAttribute;
import org.jgroups.annotations.Property;
@@ -23,7 +22,6 @@
* @author Bela Ban
* @since 3.1
*/
-@Experimental
@MBean(description="Implements synchronous acks for messages which have their RSVP flag set)")
public class RSVP extends Protocol {
View
1  src/org/jgroups/protocols/STOMP.java
@@ -27,7 +27,6 @@
* @since 2.11
*/
@MBean(description="Server side STOPM protocol, STOMP clients can connect to it")
-@Experimental
public class STOMP extends Protocol implements Runnable {
/* ----------------------------------------- Properties ----------------------------------------------- */
View
10 src/org/jgroups/protocols/TP.java
@@ -5,6 +5,7 @@
import org.jgroups.annotations.*;
import org.jgroups.blocks.LazyRemovalCache;
import org.jgroups.conf.PropertyConverters;
+import org.jgroups.logging.LogFactory;
import org.jgroups.stack.DiagnosticsHandler;
import org.jgroups.stack.Protocol;
import org.jgroups.util.*;
@@ -503,6 +504,9 @@ public void clearDifferentVersionCache() {
suppress_log_different_version.getCache().clear();
}
+
+ @ManagedAttribute(description="Type of logger used")
+ public static String loggerType() {return LogFactory.loggerType();}
/* --------------------------------------------- Fields ------------------------------------------------------ */
@@ -1333,7 +1337,7 @@ protected void passMessageUp(Message msg, String cluster_name, boolean perform_c
suppress_time_different_cluster_warnings,
cluster_name, channel_name, sender);
else
- log.warn(Util.getMessage("MsgDroppedDiffCluster", cluster_name, channel_name, sender));
+ log.warn(Util.getMessage("MsgDroppedDiffCluster"), cluster_name, channel_name, sender);
}
return;
}
@@ -1366,7 +1370,7 @@ protected void passBatchUp(MessageBatch batch, boolean perform_cluster_name_matc
suppress_time_different_cluster_warnings,
ch_name, channel_name, sender);
else
- log.warn(Util.getMessage("BatchDroppedDiffCluster", ch_name, channel_name, sender));
+ log.warn(Util.getMessage("BatchDroppedDiffCluster"), ch_name, channel_name, sender);
}
return;
}
@@ -1404,7 +1408,7 @@ protected void receive(Address sender, byte[] data, int offset, int length) {
suppress_time_different_version_warnings,
sender, Version.print(version), Version.printVersion());
else
- log.warn(Util.getMessage("VersionMismatch", sender, Version.print(version), Version.printVersion()));
+ log.warn(Util.getMessage("VersionMismatch"), sender, Version.print(version), Version.printVersion());
}
return;
}
View
42 src/org/jgroups/protocols/UDP.java
@@ -9,6 +9,7 @@
import java.io.IOException;
import java.net.*;
+import java.util.Formatter;
import java.util.List;
import java.util.Map;
@@ -388,7 +389,8 @@ protected void createSockets() throws Exception {
}
setBufferSizes();
- if(log.isDebugEnabled()) log.debug("socket information:\n" + dumpSocketInfo());
+ if(log.isDebugEnabled())
+ log.debug("socket information:\n" + dumpSocketInfo());
}
@@ -498,23 +500,18 @@ protected DatagramSocket createDatagramSocketWithBindPort() throws Exception {
protected String dumpSocketInfo() throws Exception {
StringBuilder sb=new StringBuilder(128);
- sb.append(", mcast_addr=").append(mcast_addr);
- sb.append(", bind_addr=").append(bind_addr);
- sb.append(", ttl=").append(ip_ttl);
-
- if(sock != null) {
- sb.append("\nsock: bound to ");
- sb.append(sock.getLocalAddress().getHostAddress()).append(':').append(sock.getLocalPort());
- sb.append(", receive buffer size=").append(sock.getReceiveBufferSize());
- sb.append(", send buffer size=").append(sock.getSendBufferSize());
- }
+ Formatter formatter=new Formatter(sb);
+ formatter.format("mcast_addr=%s, bind_addr=%s, ttl=%d", mcast_addr, bind_addr, ip_ttl);
- if(mcast_sock != null) {
- sb.append("\nmcast_sock: bound to ");
- sb.append(mcast_sock.getInterface().getHostAddress()).append(':').append(mcast_sock.getLocalPort());
- sb.append(", send buffer size=").append(mcast_sock.getSendBufferSize());
- sb.append(", receive buffer size=").append(mcast_sock.getReceiveBufferSize());
- }
+ if(sock != null)
+ formatter.format("\nsock: bound to %s:%d, receive buffer size=%d, send buffer size=%d",
+ sock.getLocalAddress().getHostAddress(), sock.getLocalPort(),
+ sock.getReceiveBufferSize(), sock.getSendBufferSize());
+
+ if(mcast_sock != null)
+ formatter.format("\nmcast_sock: bound to %s:%d, send buffer size=%d, receive buffer size=%d",
+ mcast_sock.getInterface().getHostAddress(), mcast_sock.getLocalPort(),
+ mcast_sock.getSendBufferSize(), mcast_sock.getReceiveBufferSize());
return sb.toString();
}
@@ -532,8 +529,8 @@ protected void setBufferSize(DatagramSocket sock, int send_buf_size, int recv_bu
sock.setSendBufferSize(send_buf_size);
int actual_size=sock.getSendBufferSize();
if(actual_size < send_buf_size && log.isWarnEnabled()) {
- log.warn(Util.getMessage("IncorrectBufferSize", "send", sock.getClass().getSimpleName(),
- Util.printBytes(send_buf_size), Util.printBytes(actual_size), "send", "net.core.wmem_max"));
+ log.warn(Util.getMessage("IncorrectBufferSize"), "send", sock.getClass().getSimpleName(),
+ Util.printBytes(send_buf_size), Util.printBytes(actual_size), "send", "net.core.wmem_max");
}
}
catch(Throwable ex) {
@@ -544,8 +541,8 @@ protected void setBufferSize(DatagramSocket sock, int send_buf_size, int recv_bu
sock.setReceiveBufferSize(recv_buf_size);
int actual_size=sock.getReceiveBufferSize();
if(actual_size < recv_buf_size && log.isWarnEnabled()) {
- log.warn(Util.getMessage("IncorrectBufferSize", "receive", sock.getClass().getSimpleName(),
- Util.printBytes(recv_buf_size), Util.printBytes(actual_size), "receive", "net.core.rmem_max"));
+ log.warn(Util.getMessage("IncorrectBufferSize"), "receive", sock.getClass().getSimpleName(),
+ Util.printBytes(recv_buf_size), Util.printBytes(actual_size), "receive", "net.core.rmem_max");
}
}
catch(Throwable ex) {
@@ -594,7 +591,8 @@ void startThreads() throws Exception {
void stopThreads() {
if(mcast_receiver != null)
mcast_receiver.stop();
- ucast_receiver.stop();
+ if(ucast_receiver != null)
+ ucast_receiver.stop();
}
View
10 src/org/jgroups/protocols/UNICAST.java
@@ -375,7 +375,7 @@ public Object up(Event evt) {
switch(evt.getType()) {
case Event.MSG:
Message msg=(Message)evt.getArg();
- if(msg.getDest() == null || msg.isFlagSet(Message.NO_RELIABILITY)) // only handle unicast messages
+ if(msg.getDest() == null || msg.isFlagSet(Message.Flag.NO_RELIABILITY)) // only handle unicast messages
break; // pass up
UnicastHeader hdr=(UnicastHeader)msg.getHeader(this.id);
@@ -387,7 +387,7 @@ public Object up(Event evt) {
handleDataReceived(sender, hdr.seqno, hdr.conn_id, hdr.first, msg, evt);
break;
default:
- handleUpEvent(sender,msg,hdr);
+ handleUpEvent(sender, hdr);
break;
}
return null;
@@ -396,7 +396,7 @@ public Object up(Event evt) {
}
- protected void handleUpEvent(Address sender, Message msg, UnicastHeader hdr) {
+ protected void handleUpEvent(Address sender, UnicastHeader hdr) {
switch(hdr.type) {
case UnicastHeader.DATA: // received regular message
throw new IllegalStateException("header of type DATA is not supposed to be handled by this method");
@@ -431,7 +431,7 @@ public void up(MessageBatch batch) {
if(hdr.type != UnicastHeader.DATA) {
try {
- handleUpEvent(msg.getSrc(), msg, hdr);
+ handleUpEvent(msg.getSrc(), hdr);
}
catch(Throwable t) { // we cannot let an exception terminate the processing of this batch
log.error(local_addr + ": failed handling event", t);
@@ -460,7 +460,7 @@ public Object down(Event evt) {
Address dst=msg.getDest();
/* only handle unicast messages */
- if (dst == null || msg.isFlagSet(Message.NO_RELIABILITY))
+ if (dst == null || msg.isFlagSet(Message.Flag.NO_RELIABILITY))
break;
if(!running) {
View
8 src/org/jgroups/protocols/UNICAST3.java
@@ -108,7 +108,6 @@
protected AgeOutCache<Address> cache;
- protected Future<?> connection_reaper; // closes idle connections
@@ -122,9 +121,6 @@ public void setMaxMessageBatchSize(int size) {
@ManagedAttribute
public String getMembers() {return members.toString();}
- @ManagedAttribute(description="Whether the ConnectionReaper task is running")
- public boolean isConnectionReaperRunning() {return connection_reaper != null && !connection_reaper.isDone();}
-
@ManagedAttribute(description="Returns the number of outgoing (send) connections")
public int getNumSendConnections() {
return send_table.size();
@@ -399,7 +395,7 @@ protected void handleUpEvent(Address sender, Message msg, Header hdr) {
log.trace(local_addr + " <-- CLOSE(" + sender + ": conn-id=" + hdr.conn_id + ")");
ReceiverEntry entry=recv_table.get(sender);
if(entry != null && entry.connId() == hdr.conn_id) {
- recv_table.remove(sender);
+ recv_table.remove(sender, entry);
if(log.isTraceEnabled())
log.trace(local_addr + ": removed receive connection for " + sender);
}
@@ -486,7 +482,7 @@ public Object down(Event evt) {
SenderEntry entry=send_table.get(dst);
if(entry == null || entry.state() == State.CLOSED) {
if(entry != null)
- send_table.remove(dst);
+ send_table.remove(dst, entry);
entry=new SenderEntry(getNewConnectionId());
SenderEntry existing=send_table.putIfAbsent(dst, entry);
if(existing != null)
View
2  src/org/jgroups/protocols/pbcast/GMS.java
@@ -592,7 +592,7 @@ public synchronized void installView(View new_view, Digest digest) {
setDigest(digest);
}
- if(log.isDebugEnabled()) log.debug(local_addr + ": installing view " + new_view);
+ if(log.isDebugEnabled()) log.debug(local_addr + ": installing " + new_view);
Event view_event;
synchronized(members) {
View
2  src/org/jgroups/protocols/pbcast/NAKACK.java
@@ -726,7 +726,7 @@ private void handleMessage(Message msg, NakAckHeader hdr) {
local_addr, hdr.seqno, sender, view);
}
else
- log.warn(Util.getMessage("MsgDroppedNak", local_addr, hdr.seqno, sender, view));
+ log.warn(Util.getMessage("MsgDroppedNak"), local_addr, hdr.seqno, sender, view);
}
return;
}
View
4 src/org/jgroups/protocols/pbcast/NAKACK2.java
@@ -763,7 +763,7 @@ protected void handleMessage(Message msg, NakAckHeader2 hdr) {
suppress_log_non_member.log(SuppressLog.Level.warn, sender, suppress_time_non_member_warnings,
local_addr, hdr.seqno, sender, view);
else
- log.warn(Util.getMessage("MsgDroppedNak", local_addr, hdr.seqno, sender, view));
+ log.warn(Util.getMessage("MsgDroppedNak"), local_addr, hdr.seqno, sender, view);
}
return;
}
@@ -808,7 +808,7 @@ protected void handleMessages(Address sender, List<Tuple<Long,Message>> msgs, bo
suppress_log_non_member.log(SuppressLog.Level.warn, sender, suppress_time_non_member_warnings,
local_addr, "batch", sender, view);
else
- log.warn(Util.getMessage("MsgDroppedNak", local_addr, "batch", sender, view));
+ log.warn(Util.getMessage("MsgDroppedNak"), local_addr, "batch", sender, view);
}
return;
}
View
2  src/org/jgroups/protocols/tom/TOA.java
@@ -1,7 +1,6 @@
package org.jgroups.protocols.tom;
import org.jgroups.*;
-import org.jgroups.annotations.Experimental;
import org.jgroups.annotations.MBean;
import org.jgroups.annotations.ManagedAttribute;
import org.jgroups.annotations.ManagedOperation;
@@ -23,7 +22,6 @@
* @author Pedro Ruivo
* @since 3.1
*/
-@Experimental
@MBean(description = "Implementation of Total Order Anycast based on Skeen's Algorithm")
public class TOA extends Protocol implements DeliveryProtocol {
//managers
View
14 src/org/jgroups/stack/Configurator.java
@@ -427,7 +427,7 @@ protected static Protocol createLayer(ProtocolStack stack, ProtocolConfiguration
catch(ClassNotFoundException e) {
}
if(clazz == null)
- throw new Exception(Util.getMessage("ProtocolLoadError", protocol_name, defaultProtocolName));
+ throw new Exception(String.format(Util.getMessage("ProtocolLoadError"), protocol_name, defaultProtocolName));
}
try {
@@ -456,10 +456,10 @@ else if (ordered instanceof Method) {
}
if(!properties.isEmpty())
- throw new IllegalArgumentException(Util.getMessage("ConfigurationError", protocol_name, properties));
+ throw new IllegalArgumentException(String.format(Util.getMessage("ConfigurationError"), protocol_name, properties));
}
catch(InstantiationException inst_ex) {
- throw new InstantiationException(Util.getMessage("ProtocolCreateError",protocol_name, inst_ex.getLocalizedMessage()));
+ throw new InstantiationException(String.format(Util.getMessage("ProtocolCreateError"), protocol_name, inst_ex.getLocalizedMessage()));
}
return retval;
}
@@ -1084,8 +1084,8 @@ public static void resolveAndInvokePropertyMethod(Object obj, Method method, Map
if(propertyName != null && propertyValue != null) {
String deprecated_msg=annotation.deprecatedMessage();
if(deprecated_msg != null && !deprecated_msg.isEmpty()) {
- log.warn(Util.getMessage("Deprecated", method.getDeclaringClass().getSimpleName() + "." + methodName,
- deprecated_msg));
+ log.warn(Util.getMessage("Deprecated"), method.getDeclaringClass().getSimpleName() + "." + methodName,
+ deprecated_msg);
}
}
@@ -1131,8 +1131,8 @@ public static void resolveAndAssignField(Object obj, Field field, Map<String,Str
String deprecated_msg=annotation.deprecatedMessage();
if(deprecated_msg != null && !deprecated_msg.isEmpty()) {
- log.warn(Util.getMessage("Deprecated", field.getDeclaringClass().getSimpleName() + "." + field.getName(),
- deprecated_msg));
+ log.warn(Util.getMessage("Deprecated"), field.getDeclaringClass().getSimpleName() + "." + field.getName(),
+ deprecated_msg);
}
}
View
2  src/org/jgroups/stack/IpAddress.java
@@ -33,7 +33,7 @@
* running in an untrusted environment with JNLP */
try {
String tmp=Util.getProperty(new String[]{Global.RESOLVE_DNS, "resolve.dns"}, null, null, false, "false");
- resolve_dns=Boolean.valueOf(tmp).booleanValue();
+ resolve_dns=Boolean.valueOf(tmp);
}
catch (SecurityException ex){
resolve_dns=false;
View
6 src/org/jgroups/util/SuppressLog.java
@@ -2,8 +2,6 @@
import org.jgroups.logging.Log;
-import java.text.MessageFormat;
-
/**
* Log (using {@link SuppressCache}) which suppresses (certain) messages from the same member for a given time
* @author Bela Ban
@@ -38,8 +36,8 @@ public void log(Level level, T key, long timeout, Object ... args) {
if(val == null) // key is present and hasn't expired
return;
- String message=val.count() == 1? MessageFormat.format(message_format, args) :
- MessageFormat.format(message_format, args) + " " + MessageFormat.format(suppress_format, val.count(), key, val.age());
+ String message=val.count() == 1? String.format(message_format, args) :
+ String.format(message_format, args) + " " + String.format(suppress_format, val.count(), key, val.age());
if(level == Level.error)
log.error(message);
View
12 src/org/jgroups/util/Util.java
@@ -33,7 +33,6 @@
import java.nio.channels.WritableByteChannel;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
-import java.text.MessageFormat;
import java.text.NumberFormat;
import java.util.*;
import java.util.concurrent.*;
@@ -219,11 +218,6 @@ public static String getMessage(String key) {
return key != null? resource_bundle.getString(key) : null;
}
- public static String getMessage(String key, Object ... args) {
- String msg=getMessage(key);
- return msg != null? MessageFormat.format(msg, args) : null;
- }
-
public static Protocol[] getTestStack() {
return new Protocol[]{
@@ -308,7 +302,7 @@ public static void addFlush(Channel ch, FLUSH flush) {
public static void setScope(Message msg, short scope) {
SCOPE.ScopeHeader hdr=SCOPE.ScopeHeader.createMessageHeader(scope);
msg.putHeader(Global.SCOPE_ID, hdr);
- msg.setFlag(Message.SCOPED);
+ msg.setFlag(Message.Flag.SCOPED);
}
public static short getScope(Message msg) {
@@ -1087,8 +1081,6 @@ public static Streamable readGenericStreamable(DataInput in) throws Exception {
else {
classname=in.readUTF();
clazz=ClassConfigurator.get(classname);
- if (clazz==null)
- throw new ClassNotFoundException(classname);
}
retval=(Streamable)clazz.newInstance();
@@ -1121,8 +1113,6 @@ public static void writeClass(Class<?> classObject, DataOutput out) throws Excep
else {
String classname=in.readUTF();
clazz=ClassConfigurator.get(classname);
- if(clazz == null)
- throw new ClassNotFoundException(classname);
}
return clazz;
View
38 tests/junit-functional/org/jgroups/protocols/UNICAST_MessagesToSelfTest.java
@@ -8,12 +8,13 @@
import org.jgroups.stack.Protocol;
import org.jgroups.stack.ProtocolStack;
import org.jgroups.util.Util;
-import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
/**
@@ -43,8 +44,10 @@
@Test(dataProvider="configProvider")
public void testReceptionOfAllMessages(Protocol prot) throws Throwable {
System.out.println("prot=" + prot.getClass().getSimpleName());
- ch=createChannel(prot, null);
+ ch=createChannel(prot, null).name("A");
ch.connect("UNICAST_Test.testReceptionOfAllMessages");
+ a1=ch.getAddress();
+ assert a1 != null;
_testReceptionOfAllMessages();
}
@@ -54,8 +57,10 @@ public void testReceptionOfAllMessagesWithDISCARD(Protocol prot) throws Throwabl
System.out.println("prot=" + prot.getClass().getSimpleName());
DISCARD discard=new DISCARD();
discard.setDownDiscardRate(0.1); // discard all down message with 10% probability
- ch=createChannel(prot, discard);
+ ch=createChannel(prot, discard).name("A");
ch.connect("UNICAST_Test.testReceptionOfAllMessagesWithDISCARD");
+ a1=ch.getAddress();
+ assert a1 != null;
_testReceptionOfAllMessages();
}
@@ -73,6 +78,9 @@ protected static JChannel createChannel(Protocol unicast, DISCARD discard) throw
if(discard != null)
stack.addProtocol(discard);
+
+ if(unicast instanceof UNICAST2)
+ unicast.setValue("stable_interval", 3000);
stack.addProtocol(new PING().setValue("timeout", 100))
.addProtocol(new NAKACK2().setValue("use_mcast_xmit", false))
@@ -97,7 +105,7 @@ private void _testReceptionOfAllMessages() throws Throwable {
System.out.println("==> " + i);
}
- for(int i=0; i < 10; i++) {
+ for(int i=0; i < 20; i++) {
if(r.getException() != null)
throw r.getException();
if(r.getNumberOfReceivedMessages() >= NUM_MSGS)
@@ -106,7 +114,22 @@ private void _testReceptionOfAllMessages() throws Throwable {
}
int num_received=r.getNumberOfReceivedMessages();
printStats(num_received);
- Assert.assertEquals(num_received, NUM_MSGS);
+
+ assert num_received == NUM_MSGS : "list is " + printList(r.getList()) ;
+ }
+
+
+ protected String printList(List<Integer> list) {
+ StringBuilder sb=new StringBuilder();
+ for(int i=0; i < 10; i++)
+ sb.append(list.get(i) + " ");
+
+ sb.append(" ... ");
+
+ for(int i=list.size() - 10; i < list.size(); i++)
+ sb.append(list.get(i) + " ");
+
+ return sb.toString();
}
@@ -115,9 +138,10 @@ private static void printStats(int num_received) {
}
/** Checks that messages 1 - NUM_MSGS are received in order */
- static class Receiver extends ReceiverAdapter {
+ protected static class Receiver extends ReceiverAdapter {
int num_mgs_received=0, next=1;
Throwable exception=null;
+ protected final List<Integer> list=new ArrayList<Integer>(NUM_MSGS);
public void receive(Message msg) {
if(exception != null)
@@ -128,6 +152,7 @@ public void receive(Message msg) {
exception=new Exception("expected seqno was " + next + ", but received " + seqno);
return;
}
+ list.add(seqno);
next++;
num_mgs_received++;
if(num_mgs_received % 1000 == 0)
@@ -136,6 +161,7 @@ public void receive(Message msg) {
public int getNumberOfReceivedMessages() {return num_mgs_received;}
public Throwable getException() {return exception;}
+ public List<Integer> getList() {return list;}
}
View
9 tests/junit-functional/org/jgroups/tests/LargeMergeTest.java
@@ -33,8 +33,8 @@
*/
@Test(groups=Global.FUNCTIONAL,sequential=true)
public class LargeMergeTest {
- static final int NUM=100; // number of members
- static final int MAX_PARTICIPANTS_IN_MERGE=Math.max(100, NUM / 3);
+ static final int NUM=50; // number of members
+ static final int MAX_PARTICIPANTS_IN_MERGE=NUM / 3;
protected final JChannel[] channels=new JChannel[NUM];
@@ -82,8 +82,6 @@ void setUp() throws Exception {
new DISCARD().setValue("discard_all",true),
new PING().setValue("timeout",1).setValue("num_initial_members",50)
.setValue("force_sending_discovery_rsps", true),
- //new MERGE2().setValue("min_interval",8000)
- //.setValue("max_interval",15000).setValue("merge_fast",false),
new MERGE3().setValue("min_interval",1000)
.setValue("max_interval",5000)
.setValue("max_participants_in_merge", MAX_PARTICIPANTS_IN_MERGE),
@@ -98,7 +96,6 @@ void setUp() throws Exception {
new STABLE().setValue("max_bytes",500000),
new GMS().setValue("print_local_addr",false)
.setValue("leave_timeout",100)
- // .setValue("merge_timeout", 10000)
.setValue("log_view_warnings",false)
.setValue("view_ack_collection_timeout",2000)
.setValue("log_collect_msgs",false));
@@ -135,8 +132,6 @@ public void testClusterFormationAfterMerge() {
boolean merge_completed=true;
for(int i=0; i < NUM; i++) {
- //int i=0;
- //for(;;) {
merge_completed=true;
System.out.println();
View
15 tests/util/org/jgroups/util/JUnitXMLReporter.java
@@ -31,8 +31,8 @@
protected final ConcurrentMap<Class<?>, DataOutputStream> tests=new ConcurrentHashMap<Class<?>,DataOutputStream>(100);
- public static final InheritableThreadLocal<PrintStream> stdout=new InheritableThreadLocal<PrintStream>();
- public static final InheritableThreadLocal<PrintStream> stderr=new InheritableThreadLocal<PrintStream>();
+ public static final InheritableThreadLocal<PrintStream> stdout=new InheritableThreadLocal<PrintStream>();
+ public static final InheritableThreadLocal<PrintStream> stderr=new InheritableThreadLocal<PrintStream>();
@@ -40,9 +40,9 @@
public void onStart(ITestContext context) {
output_dir=context.getOutputDirectory();
// Uncomment to delete dir created by previous run of this testsuite
- // File dir=new File(output_dir);
- // if(dir.exists())
- // deleteContents(dir);
+ File dir=new File(output_dir);
+ if(dir.exists())
+ deleteContents(dir);
try {
System.setOut(new MyOutput(1));
@@ -270,7 +270,7 @@ protected static void process(File dir) throws IOException {
Writer out=new FileWriter(xml_file);
String classname=dir.getName();
String suffix=parent.getName();
- if(suffix != null && suffix.length() > 0)
+ if(suffix != null && !suffix.isEmpty())
classname=classname + "-" + suffix;
try {
generateReport(out, classname, test_cases, stdout_reader, stderr_reader);
@@ -517,8 +517,7 @@ public void write(final byte[] b, final int off, final int len) {
}
public void write(final int b) {
- Integer i = new Integer(b) ;
- append(i.toString(), false) ;
+ append(String.valueOf(b), false) ;
}
public void println(String s) {
Please sign in to comment.
Something went wrong with that request. Please try again.