Skip to content

Commit a033285

Browse files
Relaxed finality of some classes in AMQP appender module.
1 parent 8b3e154 commit a033285

File tree

4 files changed

+91
-17
lines changed

4 files changed

+91
-17
lines changed

logback-amqp-appender/src/main/java/ch/qos/logback/amqp/AmqpAppender.java

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,67 @@
1616
import ch.qos.logback.core.UnsynchronizedAppenderBase;
1717

1818

19-
public final class AmqpAppender
19+
public class AmqpAppender
2020
extends UnsynchronizedAppenderBase<ILoggingEvent>
2121
{
2222
public AmqpAppender ()
2323
{
2424
super ();
25-
this.serializer = new DefaultBinarySerializer ();
2625
this.buffer = new LinkedBlockingDeque<AmqpMessage> ();
2726
this.exchangeLayout = new PatternLayout ();
2827
this.routingKeyLayout = new PatternLayout ();
2928
this.exchangeLayout.setPattern (AmqpAppender.defaultExchangeKeyPattern);
3029
this.routingKeyLayout.setPattern (AmqpAppender.defaultRoutingKeyPattern);
3130
this.mutator = new DefaultMutator ();
31+
this.serializer = new DefaultBinarySerializer ();
3232
this.publisher = null;
3333
}
3434

35+
public final String getExchangePattern ()
36+
{
37+
return (this.exchangeLayout.getPattern ());
38+
}
39+
40+
public final String getHost ()
41+
{
42+
return (this.host);
43+
}
44+
3545
public final Mutator getMutator ()
3646
{
3747
return (this.mutator);
3848
}
3949

50+
public final String getPassword ()
51+
{
52+
return (this.password);
53+
}
54+
55+
public final Integer getPort ()
56+
{
57+
return (this.port);
58+
}
59+
60+
public final String getRoutingKeyPattern ()
61+
{
62+
return (this.routingKeyLayout.getPattern ());
63+
}
64+
65+
public final Serializer getSerializer ()
66+
{
67+
return (this.serializer);
68+
}
69+
70+
public final String getUsername ()
71+
{
72+
return (this.username);
73+
}
74+
75+
public final String getVirtualHost ()
76+
{
77+
return (this.virtualHost);
78+
}
79+
4080
public final boolean isDrained ()
4181
{
4282
return (this.buffer.isEmpty ());
@@ -99,6 +139,13 @@ public final void setRoutingKeyPattern (final String pattern)
99139
this.routingKeyLayout.setPattern (pattern);
100140
}
101141

142+
public final void setSerializer (final Serializer serializer)
143+
{
144+
if (this.isStarted ())
145+
throw (new IllegalStateException ("amqp appender is already started"));
146+
this.serializer = serializer;
147+
}
148+
102149
public final void setUsername (final String username)
103150
{
104151
if (this.isStarted ())
@@ -127,6 +174,7 @@ public final void start ()
127174
new DefaultContextAwareCallbacks (this), this.buffer);
128175
this.publisher.start ();
129176
super.start ();
177+
this.started ();
130178
}
131179

132180
public final void stop ()
@@ -137,6 +185,7 @@ public final void stop ()
137185
this.routingKeyLayout.stop ();
138186
this.publisher.stop ();
139187
super.stop ();
188+
this.stopped ();
140189
}
141190

142191
protected final void append (final ILoggingEvent originalEvent)
@@ -160,6 +209,12 @@ protected final void append (final ILoggingEvent originalEvent)
160209
}
161210
}
162211

212+
protected void started ()
213+
{}
214+
215+
protected void stopped ()
216+
{}
217+
163218
private final PubLoggingEventVO prepare (final ILoggingEvent originalEvent)
164219
{
165220
final PubLoggingEventVO newEvent = PubLoggingEventVO.build (originalEvent);
@@ -176,7 +231,7 @@ private final PubLoggingEventVO prepare (final ILoggingEvent originalEvent)
176231
private Integer port;
177232
private AmqpPublisher publisher;
178233
private final PatternLayout routingKeyLayout;
179-
private final Serializer serializer;
234+
private Serializer serializer;
180235
private String username;
181236
private String virtualHost;
182237

logback-amqp-appender/src/main/java/ch/qos/logback/amqp/tools/DefaultBinarySerializer.java

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
import java.io.Serializable;
1010

1111

12-
public final class DefaultBinarySerializer
12+
public class DefaultBinarySerializer
1313
implements
1414
Serializer
1515
{
16-
public final Serializable deserialize (final byte[] data)
16+
public Serializable deserialize (final byte[] data)
1717
throws Throwable
1818
{
1919
final ByteArrayInputStream stream = new ByteArrayInputStream (data);
@@ -22,17 +22,22 @@ public final Serializable deserialize (final byte[] data)
2222
return (object);
2323
}
2424

25-
public final String getContentEncoding ()
25+
public String getContentEncoding ()
2626
{
2727
return (this.contentEncoding);
2828
}
2929

30-
public final String getContentType ()
30+
public String getContentType ()
3131
{
3232
return (this.contentType);
3333
}
3434

35-
public final byte[] serialize (final Serializable object)
35+
public int getDefaultBufferSize ()
36+
{
37+
return (this.defaultBufferSize);
38+
}
39+
40+
public byte[] serialize (final Serializable object)
3641
throws Throwable
3742
{
3843
final ByteArrayOutputStream stream = new ByteArrayOutputStream (this.defaultBufferSize);
@@ -42,7 +47,22 @@ public final byte[] serialize (final Serializable object)
4247
return (stream.toByteArray ());
4348
}
4449

45-
public final String contentEncoding = "binary";
46-
public final String contentType = "application/x-java-serialized-object";
47-
public final int defaultBufferSize = 2048;
50+
public void setContentEncoding (final String contentEncoding)
51+
{
52+
this.contentEncoding = contentEncoding;
53+
}
54+
55+
public void setContentType (final String contentType)
56+
{
57+
this.contentType = contentType;
58+
}
59+
60+
public void setDefaultBufferSize (final int defaultBufferSize)
61+
{
62+
this.defaultBufferSize = defaultBufferSize;
63+
}
64+
65+
protected String contentEncoding = "binary";
66+
protected String contentType = "application/x-java-serialized-object";
67+
protected int defaultBufferSize = 2048;
4868
}

logback-amqp-appender/src/main/java/ch/qos/logback/amqp/tools/DefaultContextAwareCallbacks.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import ch.qos.logback.core.spi.ContextAware;
77

88

9-
public final class DefaultContextAwareCallbacks
9+
public class DefaultContextAwareCallbacks
1010
implements
1111
Callbacks
1212
{
@@ -16,13 +16,12 @@ public DefaultContextAwareCallbacks (final ContextAware delegate)
1616
this.delegate = delegate;
1717
}
1818

19-
public final void handleException (
20-
final Throwable exception, final String messageFormat, final Object ... messageArguments)
19+
public void handleException (final Throwable exception, final String messageFormat, final Object ... messageArguments)
2120
{
2221
this.handleLogEvent (Level.ERROR, exception, messageFormat, messageArguments);
2322
}
2423

25-
public final void handleLogEvent (
24+
public void handleLogEvent (
2625
final Level level, final Throwable exception, final String messageFormat, final Object ... messageArguments)
2726
{
2827
final String message = String.format (messageFormat, messageArguments);
@@ -54,5 +53,5 @@ public final void handleLogEvent (
5453
}
5554
}
5655

57-
private final ContextAware delegate;
56+
protected ContextAware delegate;
5857
}

logback-amqp-appender/src/main/java/ch/qos/logback/amqp/tools/DefaultMutator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void setNode (final String node)
8181
protected String application;
8282
protected String component;
8383
protected String node;
84-
private long sequence;
84+
protected long sequence;
8585

8686
public static final String applicationKey = "application";
8787
public static final String componentKey = "component";

0 commit comments

Comments
 (0)