-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add activity lifecycle logger
- Loading branch information
Jan Rehwaldt
committed
Feb 28, 2011
1 parent
8dda625
commit 6c17839
Showing
6 changed files
with
164 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,5 @@ | ||
/target | ||
/test-output | ||
/testlog.txt | ||
/benchmark.txt | ||
|
||
/bin | ||
/engine-core-api/target | ||
/engine-core-api/bin | ||
/engine-core-impl/target | ||
/engine-core-impl/target | ||
/engine-core-impl/testlog.txt | ||
|
||
test-output | ||
target | ||
bin | ||
reports | ||
logs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
engine-core-impl/src/main/java/de/hpi/oryxengine/plugin/ActivityLifecycleLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package de.hpi.oryxengine.plugin; | ||
|
||
import java.util.Observable; | ||
import java.util.Observer; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import org.apache.log4j.Level; | ||
import org.apache.log4j.Logger; | ||
|
||
import de.hpi.oryxengine.activity.AbstractActivityImpl; | ||
import de.hpi.oryxengine.activity.ExecutionState; | ||
|
||
/** | ||
* This class is a logger and may be injected to observe | ||
* the lifecycle of certain activities. | ||
*/ | ||
public final class ActivityLifecycleLogger | ||
implements Observer { | ||
|
||
private static ActivityLifecycleLogger instance; | ||
|
||
private final Logger logger = Logger.getLogger(getClass()); | ||
private final Level level = Level.DEBUG; | ||
|
||
/** | ||
* Hide singleton constructor. | ||
*/ | ||
private ActivityLifecycleLogger() { | ||
|
||
} | ||
|
||
/** | ||
* Returns a lazily initialized logger instance. | ||
* | ||
* @return a logger instance | ||
*/ | ||
public static ActivityLifecycleLogger getInstance() { | ||
if (instance == null) { | ||
instance = new ActivityLifecycleLogger(); | ||
} | ||
|
||
return instance; | ||
} | ||
|
||
/** | ||
* Register this logger instance with the provided activity. | ||
* | ||
* @param activity the observed activity | ||
*/ | ||
public void registerWithActivity(@Nonnull Observable activity) { | ||
activity.addObserver(this); | ||
} | ||
|
||
/** | ||
* This method is invoked whenever the activity's state changes. | ||
* | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public void update(@Nonnull Observable activity, | ||
@Nonnull Object state) { | ||
stateChanged((AbstractActivityImpl) activity, (ExecutionState) state); | ||
} | ||
|
||
/** | ||
* Logs the change event to the default logger. | ||
* | ||
* @param activity the activity, which changed | ||
* @param state the new state | ||
*/ | ||
private void stateChanged(@Nonnull AbstractActivityImpl activity, | ||
@Nonnull ExecutionState state) { | ||
logger.log(level, "Activity " + activity.toString() + " changed. New state: " + state.toString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters