Skip to content

Commit 809dcf1

Browse files
authored
Merge pull request #17 from rwth-acis/development
Development
2 parents 71d3e76 + be5b85b commit 809dcf1

File tree

5 files changed

+82
-63
lines changed

5 files changed

+82
-63
lines changed

build.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<property name="ivy.organisation" value="i5" />
66
<property name="ivy.module" value="las2peer" />
77
<property name="ivy.revision" value="0.5" />
8-
<property name="ivy.build.number" value="4" />
8+
<property name="ivy.build.number" value="5" />
99
<property name="ivy.deliver.revision" value="${ivy.revision}" />
1010
<property name="ivy.pom.version" value="${ivy.revision}" />
1111

src/main/java/i5/las2peer/api/Service.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import i5.las2peer.execution.L2pServiceException;
99
import i5.las2peer.execution.L2pThread;
1010
import i5.las2peer.execution.NoSuchServiceMethodException;
11+
import i5.las2peer.logging.L2pLogger;
1112
import i5.las2peer.logging.NodeObserver.Event;
1213
import i5.las2peer.p2p.AgentNotKnownException;
1314
import i5.las2peer.p2p.Node;
@@ -403,7 +404,7 @@ public void close() {
403404
}
404405

405406
/**
406-
* @deprecated Use {@link i5.las2peer.logging.L2pLogger#logEvent(Event, String)} with {@link Event#SERVICE_MESSAGE}
407+
* @deprecated Use {@link L2pLogger#logEvent(Event, String)} with {@link Event#SERVICE_MESSAGE}
407408
* instead!
408409
* <p>
409410
* Writes a log message.
@@ -416,7 +417,7 @@ protected void logMessage(String message) {
416417
}
417418

418419
/**
419-
* @deprecated Use {@link i5.las2peer.logging.L2pLogger#logEvent(Event, Agent, String)} instead!
420+
* @deprecated Use {@link L2pLogger#logEvent(Event, Agent, String)} instead!
420421
* <p>
421422
* Writes a log message. The given index (1-99) can be used to differentiate between different log
422423
* messages.
@@ -441,7 +442,7 @@ protected void logMessage(int index, Agent actingUser, String message) {
441442
}
442443

443444
/**
444-
* @deprecated Use {@link i5.las2peer.logging.L2pLogger#logEvent(Event, String)} with {@link Event#SERVICE_ERROR}
445+
* @deprecated Use {@link L2pLogger#logEvent(Event, String)} with {@link Event#SERVICE_ERROR}
445446
* instead!
446447
* <p>
447448
* Writes an error log message.
@@ -454,7 +455,7 @@ protected void logError(String message) {
454455
}
455456

456457
/**
457-
* @deprecated Use {@link i5.las2peer.logging.L2pLogger#logEvent(Event, Agent, String)} instead!
458+
* @deprecated Use {@link L2pLogger#logEvent(Event, Agent, String)} instead!
458459
* <p>
459460
* Writes an error message. The given index (1-99) can be used to differentiate between different log
460461
* messages.
@@ -479,7 +480,7 @@ protected void logError(int index, Agent actingUser, String message) {
479480
}
480481

481482
/**
482-
* @deprecated Use {@link i5.las2peer.logging.L2pLogger} instead!
483+
* @deprecated Use {@link L2pLogger} instead!
483484
* <p>
484485
* Writes an exception log message Additionally the stack trace is printed.
485486
*

src/main/java/i5/las2peer/logging/L2pLogger.java

+43-29
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public String format(LogRecord record) {
142142

143143
/**
144144
* Prints a stack trace as nicely as {@code e.printStackTrace()}, but uses the logging system as output.
145-
*
145+
*
146146
* @param e A {@code Throwable} thats stack trace should be printed.
147147
*/
148148
public synchronized void printStackTrace(Throwable e) {
@@ -153,7 +153,7 @@ public synchronized void printStackTrace(Throwable e) {
153153

154154
/**
155155
* Appends the stack trace for the given {@link Throwable} to the given {@link StringBuilder}.
156-
*
156+
*
157157
* @param sb {@code StringBuilder} as output for the stack trace.
158158
* @param e A {@code Throwable} which stack trace should be appended. If {@code null} given, nothing is appended.
159159
*/
@@ -168,7 +168,7 @@ protected static void printStackTrace(StringBuilder sb, Throwable e) {
168168

169169
/**
170170
* Just calls the parent constructor and adds the new instance to the LogManager.
171-
*
171+
*
172172
* @param name A name for the logger. This should be a dot-separated name and should normally be based on the
173173
* package name or class name of the subsystem, such as java.net or javax.swing. It may be null for
174174
* anonymous Loggers.
@@ -190,7 +190,7 @@ protected L2pLogger(String name, String resourceBundleName) throws IllegalArgume
190190

191191
/**
192192
* Same as {@link #setLogDirectory(String)} for the global static instance.
193-
*
193+
*
194194
* @param directory A directory path given as String. {@code null} is equal to "" and the class loader directory.
195195
* @throws IOException
196196
*/
@@ -200,7 +200,7 @@ public static void setGlobalLogDirectory(String directory) throws IOException {
200200

201201
/**
202202
* Sets the directory to store log files.
203-
*
203+
*
204204
* @param directory A directory path given as String. {@code null} is equal to "" and the class loader directory.
205205
* @throws IOException
206206
*/
@@ -218,7 +218,7 @@ public synchronized void setLogDirectory(String directory) throws IOException {
218218

219219
/**
220220
* Same as {@link #setLogfilePrefix(String)} for global static instance.
221-
*
221+
*
222222
* @param prefix If {@code null} is given, file logging will be disabled.
223223
* @throws IOException
224224
*/
@@ -228,7 +228,7 @@ public static void setGlobalLogfilePrefix(String prefix) throws IOException {
228228

229229
/**
230230
* Sets the prefix used to generate log files.
231-
*
231+
*
232232
* @param prefix If {@code null} is given, file logging will be disabled.
233233
* @throws IOException
234234
*/
@@ -243,7 +243,7 @@ public synchronized void setLogfilePrefix(String prefix) throws IOException {
243243

244244
/**
245245
* This method must be called each time the log file target is changed.
246-
*
246+
*
247247
* @throws IOException
248248
*/
249249
private synchronized void updateLogfileHandler() throws IOException {
@@ -277,7 +277,7 @@ private synchronized void updateLogfileHandler() throws IOException {
277277

278278
/**
279279
* This method ensures that the given directory is actually a directory and exists.
280-
*
280+
*
281281
* @param dir A path given as String for the desired directory
282282
* @throws IOException return null;
283283
*/
@@ -290,7 +290,7 @@ private static void createDir(String dir) throws IOException {
290290

291291
/**
292292
* Same as {@link #setConsoleLevel(Level)} for the global static instance.
293-
*
293+
*
294294
* @param level The log level to set.
295295
*/
296296
public static void setGlobalConsoleLevel(Level level) {
@@ -299,7 +299,7 @@ public static void setGlobalConsoleLevel(Level level) {
299299

300300
/**
301301
* Sets the log level for the console output of this logger.
302-
*
302+
*
303303
* @param level The log level to set.
304304
*/
305305
public synchronized void setConsoleLevel(Level level) {
@@ -309,7 +309,7 @@ public synchronized void setConsoleLevel(Level level) {
309309

310310
/**
311311
* Same as {@link #setLogfileLevel(Level)} for global static instance.
312-
*
312+
*
313313
* @param level The log level to set.
314314
*/
315315
public static void setGlobalLogfileLevel(Level level) {
@@ -318,7 +318,7 @@ public static void setGlobalLogfileLevel(Level level) {
318318

319319
/**
320320
* Sets the log level for the log files used in this logger.
321-
*
321+
*
322322
* @param level The log level to set.
323323
*/
324324
public synchronized void setLogfileLevel(Level level) {
@@ -361,7 +361,7 @@ public void log(LogRecord record) {
361361

362362
/**
363363
* Writes a log message. The given event can be used to differentiate between different log messages.
364-
*
364+
*
365365
* @param event used to differentiate between different log messages
366366
* @param message
367367
*/
@@ -371,7 +371,7 @@ public static void logEvent(Event event, String message) {
371371

372372
/**
373373
* Writes a log message. The given event can be used to differentiate between different log messages.
374-
*
374+
*
375375
* @param event used to differentiate between different log messages
376376
* @param actingUser can be set to null if unknown / not desired
377377
* @param message
@@ -389,10 +389,10 @@ public static void logEvent(Event event, Agent actingUser, String message) {
389389

390390
/**
391391
* Logs a message to the l2p system using the observers.
392-
*
392+
*
393393
* Since this method will/should only be used in an L2pThread, the message will come from a service or a helper, so
394394
* a SERVICE_MESSAGE is assumed. Then this message will not be monitored by the monitoring observer.
395-
*
395+
*
396396
* @param from the calling class
397397
* @param event used to differentiate between different log messages
398398
* @param message
@@ -405,11 +405,11 @@ public static void logEvent(Object from, Event event, String message) {
405405
* Writes a log message. The given event can be used to differentiate between different log messages. The
406406
* serviceAgent and actingUser can be set to {@code null} if not known. Then this message will not be monitored by
407407
* the monitoring observer.
408-
*
408+
*
409409
* This method replaces: {@link Context#logMessage(Object, int, String, Agent, Agent)},
410410
* {@link Context#logMessage(Object, String)}, {@link Context#logError(Object, int, String, Agent, Agent)},
411411
* {@link Context#logError(Object, String)}, {@link Service#logError(String message)}
412-
*
412+
*
413413
* @param from the calling class
414414
* @param event used to differentiate between different log messages
415415
* @param message
@@ -430,7 +430,7 @@ public static void logEvent(Object from, Event event, String message, Agent serv
430430
* Writes a log message. The given event can be used to differentiate between different log messages. The
431431
* serviceAgent and actingUser can be set to {@code null} if not known. Then this message will not be monitored by
432432
* the monitoring observer.
433-
*
433+
*
434434
* @param node
435435
* @param from the calling class
436436
* @param event used to differentiate between different log messages
@@ -466,20 +466,21 @@ public void log(Long timestamp, Event event, String sourceNode, Long sourceAgent
466466

467467
/**
468468
* Simple method for one log line entry. Null will be printed as "-". All values will be followed by a tab char.
469-
*
469+
*
470470
* @param o
471471
* @return a string
472472
*/
473473
private static String appendPart(Object o) {
474-
if (o == null)
474+
if (o == null) {
475475
return "-\t";
476-
else
476+
} else {
477477
return "" + o + "\t";
478+
}
478479
}
479480

480481
/**
481482
* This method returns the default {@link Formatter} currently used to format log output for console.
482-
*
483+
*
483484
* @return Returns the console formatter.
484485
*/
485486
public static Formatter getGlobalConsoleFormatter() {
@@ -488,25 +489,38 @@ public static Formatter getGlobalConsoleFormatter() {
488489

489490
/**
490491
* This method returns the default {@link Formatter} currently used to format log output for log files.
491-
*
492+
*
492493
* @return Returns the log file formatter.
493494
*/
494495
public static Formatter getGlobalLogfileFormatter() {
495496
return GLOBAL_INSTANCE.logfileFormatter;
496497
}
497498

498499
/**
499-
* This method is the recommended way to retrieve a L2pLogger instance.
500-
*
500+
* This method is used to retrieve a L2pLogger instance.
501+
*
502+
* @param cls Should be the class this instance is used with.
503+
* @return Returns a L2pLogger instance for the given class.
504+
* @throws ClassCastException If someone overloaded the loggers instance by adding some other logger implementation
505+
* with the same name. In this case you may use Java native method by calling
506+
* {@link Logger#getLogger(String)}.
507+
*/
508+
public static L2pLogger getInstance(Class<?> cls) throws ClassCastException {
509+
return getInstance(cls.getCanonicalName());
510+
}
511+
512+
/**
513+
* This method is used to retrieve a L2pLogger instance.
514+
*
501515
* @param name A name for the new logger instance. Should be the name of your current class by default. Like
502-
* L2pLogger.class.getName()
516+
* L2pLogger.class.getCanonicalName()
503517
* @return Returns a L2pLogger instance for the given name.
504518
* @throws ClassCastException If someone overloaded the loggers instance by adding some other logger implementation
505519
* with the same name. In this case you may use Java native method by calling
506520
* {@link Logger#getLogger(String)}.
507521
*/
508522
public static L2pLogger getInstance(String name) throws ClassCastException {
509-
if (name == null || name.isEmpty() || "i5.las2peer".equals(name) || !name.startsWith("i5.las2peer")) {
523+
if (name == null || name.isEmpty() || "i5.las2peer".equals(name)) {
510524
throw new IllegalArgumentException("Invalid logger name '" + name + "' given!");
511525
}
512526
L2pLogger result = null;

src/main/java/i5/las2peer/persistency/Envelope.java

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
package i5.las2peer.persistency;
22

3+
import java.io.ByteArrayInputStream;
4+
import java.io.IOException;
5+
import java.io.ObjectInputStream;
6+
import java.io.ObjectStreamClass;
7+
import java.io.Serializable;
8+
import java.nio.charset.StandardCharsets;
9+
import java.util.Date;
10+
import java.util.Enumeration;
11+
import java.util.Hashtable;
12+
import java.util.Random;
13+
14+
import javax.crypto.SecretKey;
15+
16+
import org.apache.commons.codec.binary.Base64;
17+
318
import i5.las2peer.execution.L2pThread;
419
import i5.las2peer.p2p.ArtifactNotFoundException;
520
import i5.las2peer.p2p.StorageException;
@@ -17,21 +32,6 @@
1732
import i5.simpleXML.Parser;
1833
import i5.simpleXML.XMLSyntaxException;
1934

20-
import java.io.ByteArrayInputStream;
21-
import java.io.IOException;
22-
import java.io.ObjectInputStream;
23-
import java.io.ObjectStreamClass;
24-
import java.io.Serializable;
25-
import java.nio.charset.StandardCharsets;
26-
import java.util.Date;
27-
import java.util.Enumeration;
28-
import java.util.Hashtable;
29-
import java.util.Random;
30-
31-
import javax.crypto.SecretKey;
32-
33-
import org.apache.commons.codec.binary.Base64;
34-
3535
/**
3636
* An envelope provides a secure storage for any {@link Serializable} content within the LAS2peer network.
3737
*

0 commit comments

Comments
 (0)