import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import net.pterodactylus.util.logging.Logging;
/**
* The core of jSite.
*/
public class CoreImpl implements Core, NodeListener, RequestListener {
+ /** The logger. */
+ private static final Logger logger = Logging.getLogger(CoreImpl.class.getName());
+
/** The core listeners. */
private final List<CoreListener> coreListeners = new ArrayList<CoreListener>();
* {@inheritDoc}
*/
public void addCoreListener(CoreListener coreListener) {
+ logger.log(Level.FINEST, "adding core listener: " + coreListener);
coreListeners.add(coreListener);
}
* {@inheritDoc}
*/
public void removeCoreListener(CoreListener coreListener) {
+ logger.log(Level.FINEST, "removing core listener: " + coreListener);
coreListeners.remove(coreListener);
}
* The directory the projects were loaded from
*/
private void fireLoadingProjectsDone(String directory) {
+ logger.log(Level.FINEST, "firing loadingProjectsDone event with [directory=" + directory + "]");
for (CoreListener coreListener : coreListeners) {
coreListener.loadingProjectsDone(directory);
}
* The exception that occured when loading projects
*/
private void fireLoadingProjectsFailed(String directory, Throwable throwable) {
+ logger.log(Level.FINEST, "firing loadingProjectsFailed event with [directory=" + directory + ",throwable=" + throwable + "]");
for (CoreListener coreListener : coreListeners) {
coreListener.loadingProjectsFailed(directory, throwable);
}
* The directory the projects were saved to
*/
private void fireSavingProjectsDone(String directory) {
+ logger.log(Level.FINEST, "firing savingProjectsDone event with [directory=" + directory + "]");
for (CoreListener coreListener : coreListeners) {
coreListener.savingProjectsDone(directory);
}
* The exception that occured when saving the projects
*/
private void fireSavingProjectsFailed(String directory, Throwable throwable) {
+ logger.log(Level.FINEST, "firing savingProjectsFailed event with [directory=" + directory + ",throwable=" + throwable + "]");
for (CoreListener coreListener : coreListeners) {
coreListener.savingProjectsFailed(directory, throwable);
}
* The project that was added
*/
private void fireProjectAdded(Project project) {
+ logger.log(Level.FINEST, "firing projectAdded event with [project=" + project + "]");
for (CoreListener coreListener : coreListeners) {
coreListener.projectAdded(project);
}
* The clone of the project
*/
private void fireProjectCloned(Project clonedProject, Project projectClone) {
+ logger.log(Level.FINEST, "firing projectCloned event with [clonedProject=" + clonedProject + ",projectClone=" + projectClone + "]");
for (CoreListener coreListener : coreListeners) {
coreListener.projectCloned(clonedProject, projectClone);
}
* The project that was removed
*/
private void fireProjectRemoved(Project project) {
+ logger.log(Level.FINEST, "firing projectRemoved event with [project=" + project + "]");
for (CoreListener coreListener : coreListeners) {
coreListener.projectRemoved(project);
}
* The directory the nodes were loaded from
*/
private void fireLoadingNodesDone(String directory) {
+ logger.log(Level.FINEST, "firing loadingNodesDone event with [directory=" + directory + "]");
for (CoreListener coreListener : coreListeners) {
coreListener.loadingNodesDone(directory);
}
* The exception that occured while loading the nodes
*/
private void fireLoadingNodesFailed(String directory, Throwable throwable) {
+ logger.log(Level.FINEST, "firing loadingNodesFailed event with [directory=" + directory + ",throwable=" + throwable + "]");
for (CoreListener coreListener : coreListeners) {
coreListener.loadingNodesFailed(directory, throwable);
}
* The directory the nodes were saved to
*/
private void fireSavingNodesDone(String directory) {
+ logger.log(Level.FINEST, "firing savingNodesDone event with [directory=" + directory + "]");
for (CoreListener coreListener : coreListeners) {
coreListener.savingNodesDone(directory);
}
* The exception that occured while saving the nodes
*/
private void fireSavingNodesFailed(String directory, Throwable throwable) {
+ logger.log(Level.FINEST, "firing savingNodesFailed event with [directory=" + directory + ",throwable=" + throwable + "]");
for (CoreListener coreListener : coreListeners) {
coreListener.savingProjectsFailed(directory, throwable);
}
* Notifies all core listeners that the core has loaded and is ready to run.
*/
private void fireCoreLoaded() {
+ logger.log(Level.FINEST, "firing coreLoaded event");
for (CoreListener coreListener : coreListeners) {
coreListener.coreLoaded();
}
* Notifies all listeners that the core was stopped.
*/
private void fireCoreStopped() {
+ logger.log(Level.FINEST, "firing coreStopped event");
for (CoreListener coreListener : coreListeners) {
coreListener.coreStopped();
}
* The node that was added
*/
private void fireNodeAdded(Node node) {
+ logger.log(Level.FINEST, "firing nodeAdded event with [node=" + node + "]");
for (CoreListener coreListener : coreListeners) {
coreListener.nodeAdded(node);
}
* The node that was removed
*/
private void fireNodeRemoved(Node node) {
+ logger.log(Level.FINEST, "firing nodeRemoved event with [node=" + node + "]");
for (CoreListener coreListener : coreListeners) {
coreListener.nodeRemoved(node);
}
* The node that is being connected to
*/
private void fireNodeConnecting(Node node) {
+ logger.log(Level.FINEST, "firing nodeConnecting event with [node=" + node + "]");
for (CoreListener coreListener : coreListeners) {
coreListener.nodeConnecting(node);
}
* The node that is now connected
*/
private void fireNodeConnected(Node node) {
+ logger.log(Level.FINEST, "firing nodeConnected event with [node=" + node + "]");
for (CoreListener coreListener : coreListeners) {
coreListener.nodeConnected(node);
}
* The cause of the failure
*/
private void fireNodeConnectionFailed(Node node, Throwable cause) {
+ logger.log(Level.FINEST, "firing nodeConnectionFailed event with [node=" + node + ",cause=" + cause + "]");
for (CoreListener coreListener : coreListeners) {
coreListener.nodeConnectionFailed(node, cause);
}
* if there was no exception
*/
private void fireNodeDisconnected(Node node, Throwable throwable) {
+ logger.log(Level.FINEST, "firing nodeDisconnected event with [node=" + node + ",throwable=" + throwable + "]");
for (CoreListener coreListener : coreListeners) {
coreListener.nodeDisconnected(node, throwable);
}
* {@inheritDoc}
*/
public void start() {
+ logger.log(Level.INFO, "starting core…");
try {
nodeManager.load();
fireLoadingNodesDone(nodeManager.getDirectory());
* {@inheritDoc}
*/
public void stop() {
+ logger.log(Level.INFO, "stopping core…");
try {
projectManager.save();
fireSavingProjectsDone(projectManager.getDirectory());
* {@inheritDoc}
*/
public boolean addNode(Node node) throws UnknownHostException {
+ logger.log(Level.INFO, "addNode(node=" + node + ")");
return nodeManager.addNode(node);
}
* {@inheritDoc}
*/
public void removeNode(Node node) {
+ logger.log(Level.INFO, "removeNode(node=" + node + ")");
nodeManager.removeNode(node);
}
* {@inheritDoc}
*/
public void connectToNode(Node node) {
+ logger.log(Level.INFO, "connectToNode(node=" + node + ")");
fireNodeConnecting(node);
nodeManager.connect(node);
}
* {@inheritDoc}
*/
public void disconnectFromNode(Node node) {
+ logger.log(Level.INFO, "disconnectFromNode(node=" + node + ")");
nodeManager.disconnect(node);
}
* {@inheritDoc}
*/
public void createProject() throws IOException, JSiteException {
+ logger.log(Level.INFO, "createProject()");
Project newProject = projectManager.createProject();
fireProjectAdded(newProject);
}
* {@inheritDoc}
*/
public void cloneProject(Project project) {
+ logger.log(Level.INFO, "cloneProject(project=" + project + ")");
Project projectClone = projectManager.cloneProject(project);
fireProjectCloned(project, projectClone);
}
* {@inheritDoc}
*/
public void removeProject(Project project) {
+ logger.log(Level.INFO, "removeProject(project=" + project + ")");
projectManager.removeProject(project);
fireProjectRemoved(project);
}
*/
@SuppressWarnings("unused")
private void loadConfig() {
+ logger.log(Level.INFO, "loadConfig()");
/* TODO */
}
*/
@SuppressWarnings("unused")
private void saveConfig() {
+ logger.log(Level.INFO, "saveConfig()");
/* TODO */
}