Skip to content

Commit 1a0de3b

Browse files
--
1 parent 0279f41 commit 1a0de3b

File tree

5 files changed

+53
-45
lines changed

5 files changed

+53
-45
lines changed

logback-common/src/main/java/eu/arkitech/logback/common/CompressedBinarySerializer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ public CompressedInputStream (final InputStream stream)
6060
super (stream, new Inflater ());
6161
}
6262

63-
public void close () throws IOException
63+
public void close ()
64+
throws IOException
6465
{
6566
super.close ();
6667
this.inf.end ();
@@ -75,7 +76,8 @@ public CompressedOutputStream (final OutputStream stream, final int level)
7576
super (stream, new Deflater (level));
7677
}
7778

78-
public void close () throws IOException
79+
public void close ()
80+
throws IOException
7981
{
8082
super.close ();
8183
this.def.end ();

logback-common/src/main/java/eu/arkitech/logback/common/SLoggingEvent1.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ private void writeObject (final ObjectOutputStream out)
229229

230230
public Object[] argumentArray;
231231
public StackTraceElement[] callerDataArray;
232+
public transient String key;
232233
public transient Level level;
233234
public LoggerContextVO loggerContextVO;
234235
public String loggerName;
@@ -239,7 +240,6 @@ private void writeObject (final ObjectOutputStream out)
239240
public IThrowableProxy throwableProxy;
240241
public long timeStamp;
241242
private transient String formattedMessage;
242-
public transient String key;
243243

244244
public static SLoggingEvent1 build (final ILoggingEvent original)
245245
{

logging-datastore-lucene/src/main/java/eu/arkitech/logging/datastore/lucene/BdbDatastore.java

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -142,25 +142,30 @@ public final ILoggingEvent select (final String key)
142142
try {
143143
final OperationStatus outcome = this.eventDatabase.get (null, keyEntry, eventEntry, null);
144144
if (outcome != OperationStatus.SUCCESS) {
145-
this.callbacks.handleException (new DatabaseException (), "bdb datastore encountered an error while getting the event `%s`; aborting!", key);
145+
this.callbacks.handleException (
146+
new DatabaseException (),
147+
"bdb datastore encountered an error while getting the event `%s`; aborting!", key);
146148
return (null);
147149
}
148150
} catch (final DatabaseException exception) {
149-
this.callbacks.handleException (exception, "bdb datastore encountered an error while getting the event `%s`; aborting!", key);
151+
this.callbacks.handleException (
152+
exception, "bdb datastore encountered an error while getting the event `%s`; aborting!", key);
150153
return (null);
151154
}
152155
final Object object;
153156
try {
154157
object = this.serializer.deserialize (eventEntry.getData (), eventEntry.getOffset (), eventEntry.getSize ());
155158
} catch (final Throwable exception) {
156-
this.callbacks.handleException (exception, "bdb datastore encountered an error while deserializing the event `%s`; aborting!", key);
159+
this.callbacks.handleException (
160+
exception, "bdb datastore encountered an error while deserializing the event `%s`; aborting!", key);
157161
return (null);
158162
}
159163
final ILoggingEvent event;
160164
try {
161165
event = ILoggingEvent.class.cast (object);
162166
} catch (final ClassCastException exception) {
163-
this.callbacks.handleException (exception, "bdb datastore encountered ane error while deserializing the event `%s`; aborting!", key);
167+
this.callbacks.handleException (
168+
exception, "bdb datastore encountered ane error while deserializing the event `%s`; aborting!", key);
164169
return (null);
165170
}
166171
return (event);
@@ -172,7 +177,8 @@ public final String store (final ILoggingEvent event)
172177
try {
173178
eventData = this.serializer.serialize (event);
174179
} catch (final Throwable exception) {
175-
this.callbacks.handleException (exception, "bdb datastore encountered an error while serealizing the event; aborting!");
180+
this.callbacks.handleException (
181+
exception, "bdb datastore encountered an error while serealizing the event; aborting!");
176182
return (null);
177183
}
178184
final byte[] keyBytes = this.buildKey (eventData, event.getTimeStamp ());
@@ -182,38 +188,43 @@ public final String store (final ILoggingEvent event)
182188
try {
183189
final OperationStatus outcome = this.eventDatabase.put (null, keyEntry, eventEntry);
184190
if (outcome != OperationStatus.SUCCESS) {
185-
this.callbacks.handleException (new DatabaseException (), "bdb datastore encountered an error while storing the event `%s`; aborting!", key);
191+
this.callbacks.handleException (
192+
new DatabaseException (),
193+
"bdb datastore encountered an error while storing the event `%s`; aborting!", key);
186194
return (null);
187195
}
188196
} catch (final DatabaseException exception) {
189-
this.callbacks.handleException (new DatabaseException (), "bdb datastore encountered an error while storing the event `%s`; aborting!", key);
197+
this.callbacks.handleException (
198+
new DatabaseException (), "bdb datastore encountered an error while storing the event `%s`; aborting!",
199+
key);
190200
return (null);
191201
}
192202
return (key);
193203
}
194204

195-
private final byte[] buildKey (final byte[] data, final long timestamp)
205+
final Database getLuceneBlockDatabase ()
196206
{
197-
return (this.buildKey (data, 0, data.length, timestamp));
207+
return (this.luceneBlockDatabase);
208+
}
209+
210+
final Database getLuceneFileDatabase ()
211+
{
212+
return (this.luceneFileDatabase);
198213
}
199214

200215
private final byte[] buildKey (final byte[] data, final int offset, final int size, final long timestamp)
201216
{
202-
final byte[] timestampBytes = new byte[] {
203-
(byte)((timestamp >> 56) & 0xff),
204-
(byte)((timestamp >> 48) & 0xff),
205-
(byte)((timestamp >> 40) & 0xff),
206-
(byte)((timestamp >> 32) & 0xff),
207-
(byte)((timestamp >> 24) & 0xff),
208-
(byte)((timestamp >> 16) & 0xff),
209-
(byte)((timestamp >> 8) & 0xff),
210-
(byte)((timestamp >> 0) & 0xff),
211-
};
217+
final byte[] timestampBytes =
218+
new byte[] {(byte) ((timestamp >> 56) & 0xff), (byte) ((timestamp >> 48) & 0xff),
219+
(byte) ((timestamp >> 40) & 0xff), (byte) ((timestamp >> 32) & 0xff),
220+
(byte) ((timestamp >> 24) & 0xff), (byte) ((timestamp >> 16) & 0xff),
221+
(byte) ((timestamp >> 8) & 0xff), (byte) ((timestamp >> 0) & 0xff),};
212222
final MessageDigest hasher;
213223
try {
214-
hasher = MessageDigest.getInstance (defaultHashAlgorithm);
224+
hasher = MessageDigest.getInstance (BdbDatastore.defaultHashAlgorithm);
215225
} catch (final NoSuchAlgorithmException exception) {
216-
this.callbacks.handleException (exception, "bdb datastore encountered an error while creating the key for the event; aborting!");
226+
this.callbacks.handleException (
227+
exception, "bdb datastore encountered an error while creating the key for the event; aborting!");
217228
return (null);
218229
}
219230
hasher.update (data, offset, size);
@@ -224,28 +235,24 @@ private final byte[] buildKey (final byte[] data, final int offset, final int si
224235
return (keyBytes);
225236
}
226237

227-
private final String formatKey (final byte[] bytes) {
238+
private final byte[] buildKey (final byte[] data, final long timestamp)
239+
{
240+
return (this.buildKey (data, 0, data.length, timestamp));
241+
}
242+
243+
private final String formatKey (final byte[] bytes)
244+
{
228245
final StringBuilder builder = new StringBuilder ();
229246
for (final byte b : bytes) {
230247
final String s = Integer.toHexString (b & 0xff);
231248
if (s.length () == 1)
232-
builder.append ('0') .append (s);
249+
builder.append ('0').append (s);
233250
else
234251
builder.append (s);
235252
}
236253
return (builder.toString ());
237254
}
238255

239-
final Database getLuceneBlockDatabase ()
240-
{
241-
return (this.luceneBlockDatabase);
242-
}
243-
244-
final Database getLuceneFileDatabase ()
245-
{
246-
return (this.luceneFileDatabase);
247-
}
248-
249256
private final Callbacks callbacks;
250257
private Environment environment;
251258
private final EnvironmentConfig environmentConfiguration;
@@ -261,9 +268,9 @@ final Database getLuceneFileDatabase ()
261268
private final Serializer serializer;
262269

263270
public static final String defaultEventDatabaseName = "events";
271+
public static final String defaultHashAlgorithm = "MD5";
264272
public static final String defaultLuceneBlockDatabaseName = "lucene-blocks";
265273
public static final String defaultLuceneFileDatabaseName = "lucene-files";
266-
public static final String defaultHashAlgorithm = "MD5";
267274

268275
private final class Callbacks
269276
implements

logging-datastore-lucene/src/main/java/eu/arkitech/logging/datastore/lucene/LuceneDatastore.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
import java.io.File;
66
import java.util.List;
77

8-
import eu.arkitech.logback.common.DefaultBinarySerializer;
9-
108
import ch.qos.logback.classic.spi.ILoggingEvent;
119
import ch.qos.logback.core.filter.Filter;
1210
import eu.arkitech.logback.common.CompressedBinarySerializer;
11+
import eu.arkitech.logback.common.DefaultBinarySerializer;
1312
import eu.arkitech.logback.common.Serializer;
1413
import eu.arkitech.logging.datastore.common.Datastore;
1514
import org.apache.lucene.queryParser.ParseException;
@@ -96,15 +95,15 @@ public final ILoggingEvent select (final String key)
9695
public final String store (final ILoggingEvent event)
9796
{
9897
final String key = this.bdb.store (event);
99-
if (key != null && this.index != null)
98+
if ((key != null) && (this.index != null))
10099
this.index.store (key, event);
101100
return (key);
102101
}
103102

104-
private final boolean indexed;
105-
private final int compressed;
106103
private final BdbDatastore bdb;
104+
private final int compressed;
107105
private final LuceneIndex index;
106+
private final boolean indexed;
108107
private final File path;
109108
private final Serializer serializer;
110109
}

logging-datastore-lucene/src/main/java/eu/arkitech/logging/datastore/lucene/LuceneIndex.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import java.util.LinkedList;
77
import java.util.List;
88

9-
import org.apache.lucene.search.TopDocs;
10-
119
import ch.qos.logback.classic.spi.ILoggingEvent;
1210
import ch.qos.logback.classic.spi.IThrowableProxy;
1311
import com.sleepycat.je.Database;
@@ -26,6 +24,7 @@
2624
import org.apache.lucene.search.IndexSearcher;
2725
import org.apache.lucene.search.Query;
2826
import org.apache.lucene.search.ScoreDoc;
27+
import org.apache.lucene.search.TopDocs;
2928
import org.apache.lucene.store.je.JEDirectory;
3029
import org.apache.lucene.util.Version;
3130
import org.slf4j.Logger;
@@ -136,7 +135,8 @@ public final List<LuceneQueryResult> query (final Query query, final int maxCoun
136135
if (event != null)
137136
results.add (new LuceneQueryResult (key, event, scores[i]));
138137
else
139-
this.callbacks.handleException (new Throwable (), "lucene indexer couldn't retrieve the document `%s`; ignoring!", key);
138+
this.callbacks.handleException (
139+
new Throwable (), "lucene indexer couldn't retrieve the document `%s`; ignoring!", key);
140140
}
141141
return (results);
142142
}

0 commit comments

Comments
 (0)