Skip to content
Snippets Groups Projects
Commit adf629b0 authored by dgelessus's avatar dgelessus
Browse files

Remove unused server trace stuff

parent ea00a761
No related branches found
No related tags found
No related merge requests found
...@@ -10,8 +10,6 @@ import java.io.File; ...@@ -10,8 +10,6 @@ import java.io.File;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.osgi.service.prefs.Preferences;
import de.prob.core.command.IComposableCommand; import de.prob.core.command.IComposableCommand;
import de.prob.core.domainobjects.History; import de.prob.core.domainobjects.History;
import de.prob.core.domainobjects.MachineDescription; import de.prob.core.domainobjects.MachineDescription;
...@@ -20,10 +18,10 @@ import de.prob.core.domainobjects.RandomSeed; ...@@ -20,10 +18,10 @@ import de.prob.core.domainobjects.RandomSeed;
import de.prob.core.domainobjects.State; import de.prob.core.domainobjects.State;
import de.prob.core.internal.Activator; import de.prob.core.internal.Activator;
import de.prob.core.internal.AnimatorImpl; import de.prob.core.internal.AnimatorImpl;
import de.prob.core.internal.ServerTraceConnection; import de.prob.core.internal.ServerConnection;
import de.prob.core.internal.TraceConnectionProvider;
import de.prob.exceptions.ProBException; import de.prob.exceptions.ProBException;
import org.osgi.service.prefs.Preferences;
/** /**
* Animator is a singleton Proxy used to communicate with ProB. The method * Animator is a singleton Proxy used to communicate with ProB. The method
...@@ -41,10 +39,6 @@ public final class Animator { ...@@ -41,10 +39,6 @@ public final class Animator {
private static Animator animator = new Animator(); private static Animator animator = new Animator();
private static Animator auxanimator = null; private static Animator auxanimator = null;
/**
*
*/
private IConnectionProvider connectionProvider = null;
private volatile boolean dirty; private volatile boolean dirty;
private volatile boolean rodinProjectHasErrorsOrWarnings; private volatile boolean rodinProjectHasErrorsOrWarnings;
private final Map<Object, Object> dataStore = new HashMap<Object, Object>(); private final Map<Object, Object> dataStore = new HashMap<Object, Object>();
...@@ -98,7 +92,7 @@ public final class Animator { ...@@ -98,7 +92,7 @@ public final class Animator {
} }
private final synchronized void createNewImplementation(final File file) { private final synchronized void createNewImplementation(final File file) {
final AnimatorImpl impl = new AnimatorImpl(getIServerConnection(), file); final AnimatorImpl impl = new AnimatorImpl(new ServerConnection(), file);
setImplementation(impl); setImplementation(impl);
StaticListenerRegistry.registerComputationListener(getHistory()); StaticListenerRegistry.registerComputationListener(getHistory());
} }
...@@ -212,40 +206,6 @@ public final class Animator { ...@@ -212,40 +206,6 @@ public final class Animator {
return implementation; return implementation;
} }
/**
*
* @param {@link IConnectionProvider} provider
*/
public final synchronized void setConnectionProvider(
final IConnectionProvider provider) {
connectionProvider = provider;
}
/**
* @return {@link IServerConnection}, by default (that means
* <code>connectionProvider == null</code>) the
* {@link ServerTraceConnection}. If a {@link IConnectionProvider}
* is set, it is asked to provide a new IServerConnection
*
*/
private final synchronized IServerConnection getIServerConnection() {
if (connectionProvider == null) {
connectionProvider = new TraceConnectionProvider();
}
return connectionProvider.getISeverConnection();
}
/**
*
* @return {@link ITrace}, or null if the IServerConnection is not a
* {@link ServerTraceConnection}
*/
public final synchronized ITrace getTrace() {
if (implementation != null)
return implementation.getTraceImpl();
return null;
}
public final synchronized RandomSeed getRandomSeed() { public final synchronized RandomSeed getRandomSeed() {
return getImplementation().getSeed(); return getImplementation().getSeed();
} }
......
/**
* (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen,
* Heinrich Heine Universitaet Duesseldorf
* This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html)
* */
package de.prob.core;
public interface IConnectionProvider {
/**
*
* @return new {@link IServerConnection}
*/
public IServerConnection getISeverConnection();
}
/**
* (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen,
* Heinrich Heine Universitaet Duesseldorf
* This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html)
* */
package de.prob.core;
import java.util.List;
import de.prob.core.internal.Message;
public interface ITrace {
/**
* @return the List of logged messages as a String
*/
public String getTraceAsString();
/**
* @return the List of logged messages as unmodifiable List of
* {@link Message}
*/
public List<Message> getTraceAsList();
public int size();
void setMaximum(Integer max);
Integer getMaximum();
}
...@@ -12,7 +12,6 @@ import java.util.Map; ...@@ -12,7 +12,6 @@ import java.util.Map;
import de.prob.cli.CliException; import de.prob.cli.CliException;
import de.prob.core.IServerConnection; import de.prob.core.IServerConnection;
import de.prob.core.ITrace;
import de.prob.core.LanguageDependendAnimationPart; import de.prob.core.LanguageDependendAnimationPart;
import de.prob.core.ProblemHandler; import de.prob.core.ProblemHandler;
import de.prob.core.command.CommandException; import de.prob.core.command.CommandException;
...@@ -112,18 +111,6 @@ public class AnimatorImpl { ...@@ -112,18 +111,6 @@ public class AnimatorImpl {
return true; return true;
} }
public synchronized final ITrace getTraceImpl() {
final ITrace trace;
if (connector != null && connector instanceof ServerTraceConnection) {
ServerTraceConnection conn = (ServerTraceConnection) connector;
conn.preferenceToTrace("seed: " + getSeed().toString());
trace = conn.getTrace();
} else {
trace = null;
}
return trace;
}
public void setSeed(final RandomSeed seed) { public void setSeed(final RandomSeed seed) {
this.seed = seed; this.seed = seed;
} }
......
/**
* (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen,
* Heinrich Heine Universitaet Duesseldorf
* This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html)
* */
package de.prob.core.internal;
public class Message {
public static enum Type {
QUERY, ANSWER, LOG, PREFERENCE
};
private final Type type;
private final String message;
public Message(final Type type, final String message) {
this.message = message;
this.type = type;
}
public String getMessage() {
return message;
}
public Type getType() {
return type;
}
}
/**
* (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, Heinrich
* Heine Universitaet Duesseldorf This software is licenced under EPL 1.0
* (http://www.eclipse.org/org/documents/epl-v10.html)
* */
package de.prob.core.internal;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import org.eclipse.core.runtime.ILogListener;
import org.eclipse.core.runtime.IStatus;
import de.prob.cli.CliException;
import de.prob.core.ITrace;
import de.prob.core.internal.Message.Type;
import de.prob.exceptions.ProBException;
import de.prob.logging.Logger;
public class ServerTraceConnection extends ServerConnection implements
ILogListener {
private static final int TRACE_SIZE_LIMIT = 100;
private Trace trace;
@Override
public void startup(final File file) throws CliException {
super.startup(file);
trace = new Trace(TRACE_SIZE_LIMIT);
logToTrace("ServerTraceConnection.startup(): " + getCurrentTime());
Logger.addListener(this);
}
@Override
public void shutdown() {
super.shutdown();
logToTrace("ServerTraceConnection.shutdown(): " + getCurrentTime());
}
@Override
public String sendCommand(final String commandString) throws ProBException {
sendMessage(commandString);
return super.sendCommand(commandString);
}
@Override
protected String readAnswer() throws IOException {
String answer = super.readAnswer();
receiveMessage(answer);
return answer;
}
private void sendMessage(final String content) {
trace.addMessage(Type.QUERY, content);
}
private void receiveMessage(final String content) {
trace.addMessage(Type.ANSWER, content);
}
private final String getCurrentTime() {
SimpleDateFormat date = new SimpleDateFormat(
"yyyy.MM.dd ' - ' HH:mm:ss");
Long timemillis = System.currentTimeMillis();
return "Time: " + Long.toString(timemillis) + " - "
+ date.format(timemillis);
}
/**
* Adds a {@link Message} with the Type = LOG to the actual Tracing
* {@link ITrace}
*
* @param String
* message
*/
public final void logToTrace(final String message) {
trace.addMessage(Type.LOG, message);
}
/**
* Adds a {@link Message} with the Type = PREFERENCE to the actual Tracing
* {@link ITrace}
*
* @param String
* message
*/
public final void preferenceToTrace(final String message) {
trace.addMessageOnTop(Type.PREFERENCE, message);
}
/**
*
* @return {@link ITrace}, containing all Logs, Queries and Answers that
* passed this ServerTraceConnection
*/
public final ITrace getTrace() {
logToTrace(getCurrentTime());
return trace;
}
/**
* Adds a Error-Log-Message to the trace
*/
public void logging(final IStatus status, final String plugin) {
if (status.getSeverity() == IStatus.ERROR) {
StringBuffer message = new StringBuffer();
message.append(status.getMessage());
if (status.getException() != null) {
message.append("\n");
message.append(status.getException().getLocalizedMessage());
}
logToTrace(message.toString());
}
}
}
/**
* (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen,
* Heinrich Heine Universitaet Duesseldorf
* This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html)
* */
package de.prob.core.internal;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import de.prob.core.ITrace;
import de.prob.core.internal.Message.Type;
/**
* TODO: Maybe a part of the trace should be dumped to a file, to prevent a high
* memory consumption.
*/
public class Trace implements ITrace {
private final LinkedList<Message> list = new LinkedList<Message>();
private Integer maximum;
public Trace() {
this(null);
}
public Trace(final int maximum) {
this(Integer.valueOf(maximum));
}
private Trace(final Integer maximum) {
this.maximum = maximum;
}
/**
* @return the List of logged messages as unmodifiable List of Strings
*/
public final List<Message> getTraceAsList() {
return Collections.unmodifiableList(list);
}
/**
* @return the List of logged messages as a String
*/
public final String getTraceAsString() {
StringBuffer buffer = new StringBuffer();
for (Message message : list) {
buffer.append(starterString(message.getType()));
buffer.append(message.getMessage());
buffer.append(stopperString(message.getType()));
}
return buffer.toString();
}
public final void addMessage(final Type type, final String message) {
list.add(new Message(type, message));
limit();
}
public final void addMessageOnTop(final Type type, final String message) {
list.add(1, new Message(type, message));
limit();
}
private final String starterString(final Type type) {
return "@START " + type + "\n";
}
private final String stopperString(final Type type) {
return "\n@END " + type + "\n";
}
public static final ITrace traceFromStream(final InputStream stream) {
final Trace trace = new Trace();
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(stream));
iterateOverLines(trace, reader);
} catch (IOException e) {
System.out.println(trace.getClass().getName()
+ ": IOException at Filehandling");
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
// IGNORE
}
}
}
return trace;
}
private static void iterateOverLines(final Trace trace,
final BufferedReader reader) throws IOException {
StringBuffer buffer = new StringBuffer();
String line = reader.readLine();
while (null != line) {
final boolean restartBuffer = collect(line, trace, buffer);
if (restartBuffer) {
buffer = new StringBuffer();
}
line = reader.readLine();
}
}
private static final boolean collect(final String line, final Trace trace,
final StringBuffer buffer) {
final boolean restartBuffer;
if (line.startsWith("@START")) {
restartBuffer = true;
} else {
restartBuffer = false;
Type type;
if (line.startsWith("@END ")) {
final String typeString = line.substring(5);
try {
type = Type.valueOf(typeString);
} catch (IllegalArgumentException e) {
// the string does not represent one of our types
type = null;
}
} else {
type = null;
}
if (type != null) {
trace.addMessage(type, buffer.toString());
} else {
buffer.append(line);
}
}
return restartBuffer;
}
public int size() {
return list == null ? 0 : list.size();
}
@Override
public void setMaximum(final Integer max) {
if (max != null && max < 0)
throw new IllegalArgumentException("Non-negative maximum expected");
maximum = max;
limit();
}
private void limit() {
if (maximum != null && list != null) {
final int toRemove = list.size() - maximum;
for (int i = 0; i < toRemove; i++) {
list.removeFirst();
}
}
}
@Override
public Integer getMaximum() {
return maximum;
}
}
/**
* (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen,
* Heinrich Heine Universitaet Duesseldorf
* This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html)
* */
package de.prob.core.internal;
import de.prob.core.IConnectionProvider;
import de.prob.core.IServerConnection;
/**
* Provides a new {@link ServerTraceConnection}
*/
public class TraceConnectionProvider implements IConnectionProvider {
/**
*
* @return new {@link ServerTraceConnection}
*/
public final IServerConnection getISeverConnection() {
ServerTraceConnection conn = new ServerTraceConnection();
return conn;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment