EMMA Coverage Report (generated Wed Feb 26 21:48:09 GMT 2014)
[all classes][uk.org.simonsite.log4j.appender]

COVERAGE SUMMARY FOR SOURCE FILE [ActiveAsynchronousAppenderComponentFactory.java]

nameclass, %method, %block, %line, %
ActiveAsynchronousAppenderComponentFactory.java83%  (5/6)100% (17/17)68%  (172/253)56%  (35/63)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ActiveAsynchronousAppenderComponentFactory100% (1/1)100% (5/5)61%  (126/207)45%  (23/51)
construct (String): ExecutingAppenderAttachable 100% (1/1)29%  (10/35)18%  (2/11)
construct (String, ActiveAsynchronousAppenderProperties): LoggingEventQueue 100% (1/1)36%  (24/66)11%  (2/19)
create (ActiveAsynchronousAppenderProperties): ActiveAsynchronousAppenderComp... 100% (1/1)84%  (75/89)89%  (16/18)
ActiveAsynchronousAppenderComponentFactory (): void 100% (1/1)100% (3/3)100% (2/2)
usingMessage (String, ActiveAsynchronousAppenderProperties): String 100% (1/1)100% (14/14)100% (1/1)
     
class ActiveAsynchronousAppenderComponentFactory$10%   (0/1)100% (0/0)100% (0/0)100% (0/0)
     
class ActiveAsynchronousAppenderComponentFactory$BackportUtilConcurrentFactory100% (1/1)100% (3/3)100% (11/11)100% (3/3)
ActiveAsynchronousAppenderComponentFactory$BackportUtilConcurrentFactory (): ... 100% (1/1)100% (4/4)100% (1/1)
createAppenderAttachable (): ExecutingAppenderAttachable 100% (1/1)100% (3/3)100% (1/1)
createLoggingEventQueue (ActiveAsynchronousAppenderProperties): LoggingEventQ... 100% (1/1)100% (4/4)100% (1/1)
     
class ActiveAsynchronousAppenderComponentFactory$CompareAndSwapFactory100% (1/1)100% (3/3)100% (11/11)100% (3/3)
ActiveAsynchronousAppenderComponentFactory$CompareAndSwapFactory (): void 100% (1/1)100% (4/4)100% (1/1)
createAppenderAttachable (): ExecutingAppenderAttachable 100% (1/1)100% (3/3)100% (1/1)
createLoggingEventQueue (ActiveAsynchronousAppenderProperties): LoggingEventQ... 100% (1/1)100% (4/4)100% (1/1)
     
class ActiveAsynchronousAppenderComponentFactory$Concurrent5Factory100% (1/1)100% (3/3)100% (11/11)100% (3/3)
ActiveAsynchronousAppenderComponentFactory$Concurrent5Factory (): void 100% (1/1)100% (4/4)100% (1/1)
createAppenderAttachable (): ExecutingAppenderAttachable 100% (1/1)100% (3/3)100% (1/1)
createLoggingEventQueue (ActiveAsynchronousAppenderProperties): LoggingEventQ... 100% (1/1)100% (4/4)100% (1/1)
     
class ActiveAsynchronousAppenderComponentFactory$SyncFactory100% (1/1)100% (3/3)100% (13/13)100% (3/3)
ActiveAsynchronousAppenderComponentFactory$SyncFactory (): void 100% (1/1)100% (4/4)100% (1/1)
createAppenderAttachable (): ExecutingAppenderAttachable 100% (1/1)100% (4/4)100% (1/1)
createLoggingEventQueue (ActiveAsynchronousAppenderProperties): LoggingEventQ... 100% (1/1)100% (5/5)100% (1/1)

1/*
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 * 
6 *      http://www.apache.org/licenses/LICENSE-2.0
7 * 
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 */
14package uk.org.simonsite.log4j.appender;
15 
16import java.lang.reflect.InvocationTargetException;
17 
18import org.apache.log4j.helpers.LogLog;
19 
20import uk.org.simonsite.log4j.appender.sync.AppenderAttachments;
21import uk.org.simonsite.log4j.appender.sync.LoggingEventLinkedList;
22 
23/**
24 * @author <a href="mailto:simon_park_mail AT yahoo DOT co DOT uk">Simon
25 *         Park</a>
26 * @version 1.9
27 */
28abstract class ActiveAsynchronousAppenderComponentFactory {
29 
30  private static final ExecutingAppenderAttachable construct(
31      final String className) {
32    Exception exception = null;
33    try {
34      return (ExecutingAppenderAttachable) Class.forName(className, true,
35          Thread.currentThread().getContextClassLoader()).newInstance();
36    } catch (InstantiationException e) {
37      exception = e;
38    } catch (IllegalAccessException e) {
39      exception = e;
40    } catch (ClassNotFoundException e) {
41      exception = e;
42    }
43    LogLog.error("Unable to construct " + className, exception);
44    return new AppenderAttachments();
45  }
46 
47  private static final LoggingEventQueue construct(final String className,
48      final ActiveAsynchronousAppenderProperties appenderProperties) {
49    Exception exception = null;
50    try {
51      return (LoggingEventQueue) Class
52          .forName(className, true,
53              Thread.currentThread().getContextClassLoader())
54          .getConstructor(new Class[] { appenderProperties.getClass() })
55          .newInstance(new Object[] { appenderProperties });
56    } catch (NoSuchMethodException e) {
57      exception = e;
58    } catch (IllegalArgumentException e) {
59      exception = e;
60    } catch (SecurityException e) {
61      exception = e;
62    } catch (InstantiationException e) {
63      exception = e;
64    } catch (IllegalAccessException e) {
65      exception = e;
66    } catch (InvocationTargetException e) {
67      exception = e;
68    } catch (ClassNotFoundException e) {
69      exception = e;
70    }
71    LogLog.error("Unable to construct " + className, exception);
72    return new LoggingEventLinkedList(appenderProperties);
73  }
74 
75  private static final class BackportUtilConcurrentFactory extends
76      ActiveAsynchronousAppenderComponentFactory {
77    final ExecutingAppenderAttachable createAppenderAttachable() {
78      return construct("uk.org.simonsite.log4j.appender.backport.AppenderAttachments");
79    }
80 
81    final LoggingEventQueue createLoggingEventQueue(
82        final ActiveAsynchronousAppenderProperties appenderProperties) {
83      return construct(
84          "uk.org.simonsite.log4j.appender.backport.LoggingEventBlockingQueue",
85          appenderProperties);
86    }
87  }
88 
89  private static final class Concurrent5Factory extends
90      ActiveAsynchronousAppenderComponentFactory {
91    final ExecutingAppenderAttachable createAppenderAttachable() {
92      return construct("uk.org.simonsite.log4j.appender.concurrent.AppenderAttachments");
93    }
94 
95    final LoggingEventQueue createLoggingEventQueue(
96        final ActiveAsynchronousAppenderProperties appenderProperties) {
97      return construct(
98          "uk.org.simonsite.log4j.appender.concurrent.LoggingEventBlockingQueue",
99          appenderProperties);
100    }
101  }
102 
103  private static final class CompareAndSwapFactory extends
104      ActiveAsynchronousAppenderComponentFactory {
105    final ExecutingAppenderAttachable createAppenderAttachable() {
106      return construct("uk.org.simonsite.log4j.appender.concurrent.AppenderAttachments");
107    }
108 
109    final LoggingEventQueue createLoggingEventQueue(
110        final ActiveAsynchronousAppenderProperties appenderProperties) {
111      return construct(
112          "uk.org.simonsite.log4j.appender.cas.LoggingEventCASQueue",
113          appenderProperties);
114    }
115  }
116 
117  private static final class SyncFactory extends
118      ActiveAsynchronousAppenderComponentFactory {
119    final ExecutingAppenderAttachable createAppenderAttachable() {
120      return new uk.org.simonsite.log4j.appender.sync.AppenderAttachments();
121    }
122 
123    final LoggingEventQueue createLoggingEventQueue(
124        final ActiveAsynchronousAppenderProperties appenderProperties) {
125      return new uk.org.simonsite.log4j.appender.sync.LoggingEventLinkedList(
126          appenderProperties);
127    }
128  }
129 
130  static final ActiveAsynchronousAppenderComponentFactory create(
131      final ActiveAsynchronousAppenderProperties appenderProperties) {
132    // first see whether to attempt to use the backport implementation
133    if (appenderProperties.isUseBackport()) {
134      try {
135        Class
136            .forName(
137                "edu.emory.mathcs.backport.java.util.concurrent.ArrayBlockingQueue",
138                false, Thread.currentThread().getContextClassLoader());
139        LogLog.debug(usingMessage("backport-util-concurrent",
140            appenderProperties));
141        return new BackportUtilConcurrentFactory();
142      } catch (ClassNotFoundException e) {
143        LogLog.warn(
144            "backport-util-concurrent component factory not instantiated for appender "
145                + appenderProperties.getName()
146                + "; a default will be used instead; check your classpath", e);
147      }
148    }
149    // the CAS implementation is up next
150    if (appenderProperties.isUseCAS()) {
151      try {
152        Class.forName("java.util.concurrent.locks.Lock", false, Thread
153            .currentThread().getContextClassLoader());
154        LogLog.debug(usingMessage("CAS", appenderProperties));
155        return new CompareAndSwapFactory();
156      } catch (ClassNotFoundException e) {
157        LogLog.warn(
158            "Compare And Swap (CAS) component factory not instantiated for appender "
159                + appenderProperties.getName()
160                + "; a default will be used instead; check your classpath", e);
161      }
162    }
163    // see whether we're running on a 1.5+ JVM
164    try {
165      Class.forName("java.util.concurrent.locks.Lock", false, Thread
166          .currentThread().getContextClassLoader());
167      LogLog.debug(usingMessage("Java 5", appenderProperties));
168      return new Concurrent5Factory();
169    } catch (ClassNotFoundException e) {
170      // ignore and try to load the default synchronized class
171    }
172    LogLog.debug(usingMessage("Java 1.4", appenderProperties));
173    return new SyncFactory();
174  }
175 
176  private static String usingMessage(final String platformString,
177      final ActiveAsynchronousAppenderProperties properties) {
178    return "Using " + platformString
179        + " compatible component factory for appender " + properties.getName();
180  }
181 
182  private ActiveAsynchronousAppenderComponentFactory() {
183    super();
184  }
185 
186  abstract ExecutingAppenderAttachable createAppenderAttachable();
187 
188  abstract LoggingEventQueue createLoggingEventQueue(
189      ActiveAsynchronousAppenderProperties appenderProperties);
190}

[all classes][uk.org.simonsite.log4j.appender]
EMMA 2.0.5312 (C) Vladimir Roubtsov