diff --git a/de.prob.core/src/de/prob/core/Animator.java b/de.prob.core/src/de/prob/core/Animator.java index 1d49c94b2ecf95be9d2399d2d66bd8f93285d341..8311d265fab0461a948eca27e4655581d9d4d005 100644 --- a/de.prob.core/src/de/prob/core/Animator.java +++ b/de.prob.core/src/de/prob/core/Animator.java @@ -10,8 +10,6 @@ import java.io.File; import java.util.HashMap; import java.util.Map; -import org.osgi.service.prefs.Preferences; - import de.prob.core.command.IComposableCommand; import de.prob.core.domainobjects.History; import de.prob.core.domainobjects.MachineDescription; @@ -20,10 +18,10 @@ import de.prob.core.domainobjects.RandomSeed; import de.prob.core.domainobjects.State; import de.prob.core.internal.Activator; import de.prob.core.internal.AnimatorImpl; -import de.prob.core.internal.ServerTraceConnection; -import de.prob.core.internal.TraceConnectionProvider; +import de.prob.core.internal.ServerConnection; import de.prob.exceptions.ProBException; +import org.osgi.service.prefs.Preferences; /** * Animator is a singleton Proxy used to communicate with ProB. The method @@ -41,10 +39,6 @@ public final class Animator { private static Animator animator = new Animator(); private static Animator auxanimator = null; - /** - * - */ - private IConnectionProvider connectionProvider = null; private volatile boolean dirty; private volatile boolean rodinProjectHasErrorsOrWarnings; private final Map<Object, Object> dataStore = new HashMap<Object, Object>(); @@ -98,7 +92,7 @@ public final class Animator { } 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); StaticListenerRegistry.registerComputationListener(getHistory()); } @@ -212,40 +206,6 @@ public final class Animator { 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() { return getImplementation().getSeed(); } diff --git a/de.prob.core/src/de/prob/core/IConnectionProvider.java b/de.prob.core/src/de/prob/core/IConnectionProvider.java deleted file mode 100644 index 8fab6f07f31b088c6fc72f972fa2208ca2f9c1f3..0000000000000000000000000000000000000000 --- a/de.prob.core/src/de/prob/core/IConnectionProvider.java +++ /dev/null @@ -1,17 +0,0 @@ -/** - * (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(); -} diff --git a/de.prob.core/src/de/prob/core/ITrace.java b/de.prob.core/src/de/prob/core/ITrace.java deleted file mode 100644 index eb7647044dd9ef1a1339f11625b52700a4a79e9b..0000000000000000000000000000000000000000 --- a/de.prob.core/src/de/prob/core/ITrace.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * (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(); - -} diff --git a/de.prob.core/src/de/prob/core/internal/AnimatorImpl.java b/de.prob.core/src/de/prob/core/internal/AnimatorImpl.java index 639180e70eb1f2ba2ec190354abab376ef2aa2ea..2df0c76d38b381697f70ca817dff09d6bdb83d00 100644 --- a/de.prob.core/src/de/prob/core/internal/AnimatorImpl.java +++ b/de.prob.core/src/de/prob/core/internal/AnimatorImpl.java @@ -12,7 +12,6 @@ import java.util.Map; import de.prob.cli.CliException; import de.prob.core.IServerConnection; -import de.prob.core.ITrace; import de.prob.core.LanguageDependendAnimationPart; import de.prob.core.ProblemHandler; import de.prob.core.command.CommandException; @@ -112,18 +111,6 @@ public class AnimatorImpl { 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) { this.seed = seed; } diff --git a/de.prob.core/src/de/prob/core/internal/Message.java b/de.prob.core/src/de/prob/core/internal/Message.java deleted file mode 100644 index 7172c5fd7333a9f3679f681fe48d90eaa0426689..0000000000000000000000000000000000000000 --- a/de.prob.core/src/de/prob/core/internal/Message.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * (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; - } - -} diff --git a/de.prob.core/src/de/prob/core/internal/ServerTraceConnection.java b/de.prob.core/src/de/prob/core/internal/ServerTraceConnection.java deleted file mode 100644 index 4eaea64c06a770f77a8b0a52a75df0ac010367b4..0000000000000000000000000000000000000000 --- a/de.prob.core/src/de/prob/core/internal/ServerTraceConnection.java +++ /dev/null @@ -1,124 +0,0 @@ -/** - * (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()); - - } - - } -} diff --git a/de.prob.core/src/de/prob/core/internal/Trace.java b/de.prob.core/src/de/prob/core/internal/Trace.java deleted file mode 100644 index 1fa86cdfe0149f4b626f89ec205980da7c1f552c..0000000000000000000000000000000000000000 --- a/de.prob.core/src/de/prob/core/internal/Trace.java +++ /dev/null @@ -1,170 +0,0 @@ -/** - * (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; - } - -} diff --git a/de.prob.core/src/de/prob/core/internal/TraceConnectionProvider.java b/de.prob.core/src/de/prob/core/internal/TraceConnectionProvider.java deleted file mode 100644 index 25676a1c2e5c326ce925fd8d9d0b4ab849fbc5a4..0000000000000000000000000000000000000000 --- a/de.prob.core/src/de/prob/core/internal/TraceConnectionProvider.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * (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; - } - -}