Skip to content

Commit

Permalink
Refactoring System.out.println in deeco core code base to use logging…
Browse files Browse the repository at this point in the history
… methods instead
  • Loading branch information
Ilias committed Mar 12, 2013
1 parent 5587bbf commit c924380
Show file tree
Hide file tree
Showing 27 changed files with 133 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import cz.cuni.mff.d3s.deeco.knowledge.OutWrapper;
import cz.cuni.mff.d3s.deeco.knowledge.StructureHelper;
import cz.cuni.mff.d3s.deeco.knowledge.TypeUtils;
import cz.cuni.mff.d3s.deeco.logging.LoggerFactory;

public class OutputParametersHelper implements Serializable {

Expand Down Expand Up @@ -54,7 +55,7 @@ public void storeOutValue(String knowledgePath, Object orgValue,
storeOutValue(knowledgePath, ((OutWrapper<?>) orgValue).item,
((OutWrapper<?>) newValue).item, km, session);
else
System.out.println("Something is wrong!");
LoggerFactory.getLogger().info("Something is wrong!");
} else if (!(TypeUtils.isList(nvClass) || TypeUtils.isList(ovClass))) {
Object [] nvStructure = StructureHelper
.getStructureFromObject(newValue), ovStructure = StructureHelper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.lang.reflect.Method;
import java.util.List;

import cz.cuni.mff.d3s.deeco.logging.LoggerFactory;
import cz.cuni.mff.d3s.deeco.processor.MethodDescription;

/**
Expand Down Expand Up @@ -115,7 +116,7 @@ public Object invoke(Object[] parameters) {
try {
return getMethod().invoke(null, parameters);
} catch (Exception e) {
System.out.println("Method invocation error: " + e.getMessage());
LoggerFactory.getLogger().severe("Method invocation error",e);
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import cz.cuni.mff.d3s.deeco.exceptions.KMException;
import cz.cuni.mff.d3s.deeco.knowledge.ISession;
import cz.cuni.mff.d3s.deeco.knowledge.KnowledgeManager;
import cz.cuni.mff.d3s.deeco.logging.LoggerFactory;
import cz.cuni.mff.d3s.deeco.scheduling.ETriggerType;
import cz.cuni.mff.d3s.deeco.scheduling.ProcessSchedule;

Expand Down Expand Up @@ -55,7 +56,7 @@ public SchedulableComponentProcess(KnowledgeManager km, ProcessSchedule scheduli
*/
@Override
public void invoke(String triggererId, ETriggerType recipientMode) {
//System.out.println("Component process starts - " + this.toString());
//LoggerFactory.getLogger().fine("Component process starts - " + this.toString());
try {
if (lockingMode.equals(ELockingMode.STRONG)) {
ISession session = km.createSession();
Expand All @@ -66,21 +67,21 @@ public void invoke(String triggererId, ETriggerType recipientMode) {
session.end();
}
} catch (KMException e) {
System.out.println(e.getMessage());
LoggerFactory.getLogger().severe("",e);
session.cancel();
}
} else {
try {
evaluateMethod();
} catch (KMException kme) {
System.out.println("SCP message - " + kme.getMessage());
LoggerFactory.getLogger().severe("SCP message error",kme);
kme.printStackTrace();
}
}
} catch (Exception e) {
System.out.println(e.getMessage());
LoggerFactory.getLogger().severe("",e);
}
//System.out.println("Component process ends - " + this.toString());
//LoggerFactory.getLogger().fine("Component process ends - " + this.toString());
}

private void evaluateMethod() throws KMException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import cz.cuni.mff.d3s.deeco.knowledge.ConstantKeys;
import cz.cuni.mff.d3s.deeco.knowledge.ISession;
import cz.cuni.mff.d3s.deeco.knowledge.KnowledgeManager;
import cz.cuni.mff.d3s.deeco.logging.LoggerFactory;
import cz.cuni.mff.d3s.deeco.scheduling.ETriggerType;
import cz.cuni.mff.d3s.deeco.scheduling.ProcessSchedule;

Expand Down Expand Up @@ -71,7 +72,7 @@ public SchedulableEnsembleProcess(KnowledgeManager km, ProcessSchedule schedulin
*/
@Override
public void invoke(String triggererId, ETriggerType recipientMode) {
// System.out.println("Ensembling starts");
// LoggerFactory.getLogger().fine("Ensembling starts");
try {
Object[] ids = (Object[]) km
.getKnowledge(ConstantKeys.ROOT_KNOWLEDGE_ID);
Expand All @@ -82,7 +83,7 @@ public void invoke(String triggererId, ETriggerType recipientMode) {
singleInvocation(triggererId, recipientMode, ids);
} catch (KMException kme) {
}
// System.out.println("Ensembling ends");
// LoggerFactory.getLogger().fine("Ensembling ends");
} catch (KMException kme) {
return;
}
Expand Down Expand Up @@ -147,8 +148,7 @@ private boolean evaluateMembership(ParametersPair[] params) {
Object[] parameterValues = ParametersPair.extractValues(params);
return membership.membership(parameterValues);
} catch (Exception e) {
System.out.println("Ensemble membership exception! - "
+ e.getMessage());
LoggerFactory.getLogger().severe("Ensemble membership exception",e);
return false;
}
}
Expand All @@ -158,8 +158,7 @@ private void evaluateKnowledgeExchange(ParametersPair[] params) {
Object[] parameterValues = ParametersPair.extractValues(params);
knowledgeExchange.invoke(parameterValues);
} catch (Exception e) {
System.out.println("Ensemble evaluation exception! - "
+ e.getMessage());
LoggerFactory.getLogger().severe("Ensemble evaluation exception",e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import cz.cuni.mff.d3s.deeco.knowledge.ISession;
import cz.cuni.mff.d3s.deeco.knowledge.KnowledgeManager;
import cz.cuni.mff.d3s.deeco.knowledge.local.DeepCopy;
import cz.cuni.mff.d3s.deeco.logging.LoggerFactory;
import cz.cuni.mff.d3s.deeco.scheduling.ETriggerType;
import cz.cuni.mff.d3s.deeco.scheduling.ProcessPeriodicSchedule;
import cz.cuni.mff.d3s.deeco.scheduling.ProcessSchedule;
Expand Down Expand Up @@ -128,13 +129,11 @@ protected ParametersPair[] getParameterMethodValues(List<Parameter> in,
}
return result;
} catch (KMException kme) {
// System.out.println("Parameter getting error!: " +
// kme.getMessage());
if (session == null)
localSession.cancel();
throw kme;
} catch (Exception e) {
System.out.println(e.getMessage());
LoggerFactory.getLogger().severe("",e);
return null;
}
}
Expand Down Expand Up @@ -209,7 +208,7 @@ protected void putParameterMethodValues(ParametersPair[] parameterValues,
} catch (Exception e) {
if (session == null)
localSession.cancel();
System.out.println(e.getMessage());
LoggerFactory.getLogger().severe("",e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cz.cuni.mff.d3s.deeco.knowledge;

import cz.cuni.mff.d3s.deeco.exceptions.KMException;
import cz.cuni.mff.d3s.deeco.logging.LoggerFactory;
import cz.cuni.mff.d3s.deeco.scheduling.IKnowledgeChangeListener;

public class LoggingKnowledgeManager extends KnowledgeManager {
Expand All @@ -15,40 +16,40 @@ public LoggingKnowledgeManager(KnowledgeManager decoratedKm) {
@Override
public Object getKnowledge(String knowledgePath, ISession session)
throws KMException {
System.out.println("LoggingKnowledgeManager.getKnowledge(knowledgePath=" + knowledgePath +", session=" + session + ")");
LoggerFactory.getLogger().fine("LoggingKnowledgeManager.getKnowledge(knowledgePath=" + knowledgePath +", session=" + session + ")");
return decoratedKm.getKnowledge(knowledgePath, session);
}

@Override
public Object takeKnowledge(String knowledgePath, ISession session)
throws KMException {
System.out.println("LoggingKnowledgeManager.takeKnowledge(knowledgePath=" + knowledgePath +", session=" + session + ")");
LoggerFactory.getLogger().fine("LoggingKnowledgeManager.takeKnowledge(knowledgePath=" + knowledgePath +", session=" + session + ")");
return decoratedKm.takeKnowledge(knowledgePath, session);
}

@Override
public void alterKnowledge(String knowledgePath, Object value,
ISession session) throws KMException {
System.out.println("LoggingKnowledgeManager.alterKnowledge(knowledgePath=" + knowledgePath +", value=" + value + ", session=" + session + ")");
LoggerFactory.getLogger().fine("LoggingKnowledgeManager.alterKnowledge(knowledgePath=" + knowledgePath +", value=" + value + ", session=" + session + ")");
decoratedKm.alterKnowledge(knowledgePath, value, session);
}

@Override
public void putKnowledge(String knowledgePath, Object value,
ISession session) throws KMException {
System.out.println("LoggingKnowledgeManager.putKnowledge(knowledgePath=" + knowledgePath +", value=" + value + ", session=" + session + ")");
LoggerFactory.getLogger().fine("LoggingKnowledgeManager.putKnowledge(knowledgePath=" + knowledgePath +", value=" + value + ", session=" + session + ")");
decoratedKm.putKnowledge(knowledgePath, value, session);
}

@Override
public ISession createSession() {
System.out.println("LoggingKnowledgeManager.createSession()");
LoggerFactory.getLogger().fine("LoggingKnowledgeManager.createSession()");
return decoratedKm.createSession();
}

@Override
public boolean registerListener(IKnowledgeChangeListener listener) {
System.out.println("LoggingKnowledgeManager.registerListener(listener=" + listener + ")");
LoggerFactory.getLogger().fine("LoggingKnowledgeManager.registerListener(listener=" + listener + ")");
return decoratedKm.unregisterListener(listener);
}

Expand All @@ -60,33 +61,33 @@ public boolean unregisterListener(IKnowledgeChangeListener listener) {

@Override
public void setListenersActive(boolean on) {
System.out.println("LoggingKnowledgeManager.switchListening(on=" + on + ")");
LoggerFactory.getLogger().fine("LoggingKnowledgeManager.switchListening(on=" + on + ")");
decoratedKm.setListenersActive(on);
}

@Override
public Object getKnowledge(String knowledgePath) throws KMException {
System.out.println("LoggingKnowledgeManager.getKnowledge(knowledgePath=" + knowledgePath + ")");
LoggerFactory.getLogger().fine("LoggingKnowledgeManager.getKnowledge(knowledgePath=" + knowledgePath + ")");
return decoratedKm.getKnowledge(knowledgePath);
}

@Override
public Object takeKnowledge(String knowledgePath) throws KMException {
System.out.println("LoggingKnowledgeManager.takeKnowledge(knowledgePath=" + knowledgePath + ")");
LoggerFactory.getLogger().fine("LoggingKnowledgeManager.takeKnowledge(knowledgePath=" + knowledgePath + ")");
return decoratedKm.takeKnowledge(knowledgePath);
}

@Override
public void alterKnowledge(String knowledgePath, Object value)
throws KMException {
System.out.println("LoggingKnowledgeManager.alterKnowledge(knowledgePath=" + knowledgePath +", value=" + value + ")");
LoggerFactory.getLogger().fine("LoggingKnowledgeManager.alterKnowledge(knowledgePath=" + knowledgePath +", value=" + value + ")");
decoratedKm.alterKnowledge(knowledgePath, value);
}

@Override
public void putKnowledge(String knowledgePath, Object value)
throws KMException {
System.out.println("LoggingKnowledgeManager.putKnowledge(knowledgePath=" + knowledgePath +", value=" + value + ")");
LoggerFactory.getLogger().fine("LoggingKnowledgeManager.putKnowledge(knowledgePath=" + knowledgePath +", value=" + value + ")");
decoratedKm.putKnowledge(knowledgePath, value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import cz.cuni.mff.d3s.deeco.exceptions.KMNotExistentException;
import cz.cuni.mff.d3s.deeco.exceptions.KRExceptionAccessError;
import cz.cuni.mff.d3s.deeco.exceptions.KRExceptionUnavailableEntry;
import cz.cuni.mff.d3s.deeco.logging.LoggerFactory;
import cz.cuni.mff.d3s.deeco.scheduling.IKnowledgeChangeListener;

/*
Expand Down Expand Up @@ -199,7 +200,7 @@ else if (structure.length > 0) {
throw new KMAccessException(kre.getMessage());
} catch (Exception e) {
localSession.cancel();
System.out.println(e.getMessage());
LoggerFactory.getLogger().severe("",e);
}
}

Expand Down Expand Up @@ -266,7 +267,7 @@ private Object getKnowledge(boolean withdrawal, String knowledgePath,
localSession.cancel();
throw new KMAccessException(kre.getMessage());
} catch (Exception e) {
System.out.println(e.getMessage());
LoggerFactory.getLogger().severe("",e);
localSession.cancel();
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import cz.cuni.mff.d3s.deeco.knowledge.ConstantKeys;
import cz.cuni.mff.d3s.deeco.knowledge.KnowledgePathHelper;
import cz.cuni.mff.d3s.deeco.knowledge.KnowledgeRepository;
import cz.cuni.mff.d3s.deeco.logging.LoggerFactory;
import cz.cuni.mff.d3s.deeco.path.grammar.EEnsembleParty;

public class ChangeNotifier {
Expand Down Expand Up @@ -68,7 +69,7 @@ public void notifyAboutChanges(TransactionalSession session) {
updateVersion(listenPath, session, newVersion);
}
} catch (KRExceptionAccessError kre) {
System.out.println("Knowledge Repository communication exception!");
LoggerFactory.getLogger().severe("Knowledge Repository communication exception",kre);
}
notifying = false;
}
Expand All @@ -79,9 +80,9 @@ private void updateVersion(String path, TransactionalSession session,
Object value = kr.take(path, session);
value = newVersion;
kr.put(path, value, session);
System.out.println("Updating: " + path);
LoggerFactory.getLogger().info("Updating: " + path);
} catch (KRExceptionUnavailableEntry uee) {
//System.out.println("Updating error: " + path);
//LoggerFactory.getLogger().severe("Updating error: " + path);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import java.rmi.RemoteException;

import cz.cuni.mff.d3s.deeco.logging.LoggerFactory;

import net.jini.core.lookup.ServiceRegistrar;
import net.jini.core.lookup.ServiceTemplate;

Expand Down Expand Up @@ -167,6 +169,6 @@ public void discovered(DiscoveryEvent anEvent) {
new ServiceRegistrars, we do nothing here.
*/
public void discarded(DiscoveryEvent anEvent) {
System.out.println("Disappeared");
LoggerFactory.getLogger().info("Disappeared");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import cz.cuni.mff.d3s.deeco.knowledge.ISession;
import cz.cuni.mff.d3s.deeco.knowledge.KnowledgePathHelper;
import cz.cuni.mff.d3s.deeco.knowledge.KnowledgeRepository;
import cz.cuni.mff.d3s.deeco.logging.LoggerFactory;
import cz.cuni.mff.d3s.deeco.scheduling.IKnowledgeChangeListener;

/**
Expand Down Expand Up @@ -94,7 +95,7 @@ public Object[] take(String entryKey, ISession session)
if (resultList.size() == 0)
throw new KRExceptionUnavailableEntry("Entry " + entryKey
+ " unavailable!");
//System.out.println("Taking: " + entryKey);
//LoggerFactory.getLogger().fine("Taking: " + entryKey);
return resultList.toArray();
}

Expand Down Expand Up @@ -148,15 +149,15 @@ public void put(String entryKey, Object value, ISession session)
Transaction tx = (session != null) ? ((TransactionalSession) session)
.getTransaction() : null;
space.write(TSUtils.createTuple(entryKey, value), tx, Lease.FOREVER);
//System.out.println("Writing entry: " + entryKey);
//LoggerFactory.getLogger().fine("Writing entry: " + entryKey);
if (session != null)
((TransactionalSession) session).propertyChanged(entryKey, this);
} catch (Exception e) {
throw new KRExceptionAccessError(
"TSKnowledgeRepository error when writing property: "
+ entryKey + " - " + e.getMessage());
}
//System.out.println("Putting: " + entryKey);
//LoggerFactory.getLogger().fine("Putting: " + entryKey);
}

/*
Expand Down Expand Up @@ -229,7 +230,7 @@ private void addTSNotifier(String kp, TSRemoteEventListener tsListener)
space.registerForAvailabilityEvent(
Arrays.asList(new Tuple[] { TSUtils.createTemplate(fullListenPath) }), null, true,
tsListener.getStub(), Lease.FOREVER, null);
System.out.println("Listener added: " + fullListenPath);
LoggerFactory.getLogger().info("Listener added: " + fullListenPath);
} catch (Exception e) {
throw new KRExceptionAccessError(
"TSKnowledgeRepository error when adding a listener for the property: "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.jini.space.AvailabilityEvent;
import cz.cuni.mff.d3s.deeco.knowledge.KnowledgePathHelper;
import cz.cuni.mff.d3s.deeco.knowledge.KnowledgeRepository;
import cz.cuni.mff.d3s.deeco.logging.LoggerFactory;
import cz.cuni.mff.d3s.deeco.scheduling.ETriggerType;
import cz.cuni.mff.d3s.deeco.scheduling.IKnowledgeChangeListener;

Expand Down Expand Up @@ -75,7 +76,7 @@ public void notify(RemoteEvent re) throws UnknownEventException,
tObjects = kr.get(t.key, ts);
stringVersionAndOwner = (String) tObjects[0];
versionOwner = extractVersionOwner(stringVersionAndOwner);
// System.out.println("Triggered: " + t.key + " " +
// LoggerFactory.getLogger().fine("Triggered: " + t.key + " " +
// stringVersionAndOwner);
if (versionOwner != null) {
version = versionOwner[0];
Expand All @@ -95,7 +96,7 @@ public void notify(RemoteEvent re) throws UnknownEventException,
} catch (Exception e) {
if (ts != null)
ts.cancel();
System.out.println("Notification exception: " + e.getMessage());
LoggerFactory.getLogger().severe("Notification exception",e);
}
}
}
Expand Down
Loading

0 comments on commit c924380

Please sign in to comment.