From: <wu...@us...> - 2008-03-04 13:08:26
|
Revision: 71 http://davinspector.svn.sourceforge.net/davinspector/?rev=71&view=rev Author: wuest Date: 2008-03-04 05:07:57 -0800 (Tue, 04 Mar 2008) Log Message: ----------- Moved instance of the PluginManager from the view to the model and added a system logger. Modified Paths: -------------- trunk/DAVInspector/config.properties trunk/DAVInspector/src/de/dlr/davinspector/relay/ChannelThread.java trunk/DAVInspector/src/de/dlr/davinspector/relay/IRelayModel.java trunk/DAVInspector/src/de/dlr/davinspector/relay/RelayModel.java trunk/DAVInspector/src/de/dlr/davinspector/ui/MainView.java Added Paths: ----------- trunk/DAVInspector/.classpath trunk/DAVInspector/.project Added: trunk/DAVInspector/.classpath =================================================================== --- trunk/DAVInspector/.classpath (rev 0) +++ trunk/DAVInspector/.classpath 2008-03-04 13:07:57 UTC (rev 71) @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry exported="true" kind="lib" path="lib/commons-logging.jar"> + <attributes> + <attribute name="javadoc_location" value="jar:platform:/resource/DAVInspector/lib/commons-logging-javadoc.jar!/"/> + </attributes> + </classpathentry> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="output" path="bin"/> +</classpath> Added: trunk/DAVInspector/.project =================================================================== --- trunk/DAVInspector/.project (rev 0) +++ trunk/DAVInspector/.project 2008-03-04 13:07:57 UTC (rev 71) @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>DAVInspector</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>com.atlassw.tools.eclipse.checkstyle.CheckstyleBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jem.workbench.JavaEMFNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + <nature>com.atlassw.tools.eclipse.checkstyle.CheckstyleNature</nature> + <nature>org.eclipse.jem.beaninfo.BeanInfoNature</nature> + </natures> +</projectDescription> Modified: trunk/DAVInspector/config.properties =================================================================== --- trunk/DAVInspector/config.properties 2008-03-04 10:20:48 UTC (rev 70) +++ trunk/DAVInspector/config.properties 2008-03-04 13:07:57 UTC (rev 71) @@ -1,4 +1,4 @@ -#Mon Feb 04 20:56:00 CET 2008 +#Tue Mar 04 09:35:50 CET 2008 ClientPort=9999 ServerPort=8080 ServerAddress=localhost Modified: trunk/DAVInspector/src/de/dlr/davinspector/relay/ChannelThread.java =================================================================== --- trunk/DAVInspector/src/de/dlr/davinspector/relay/ChannelThread.java 2008-03-04 10:20:48 UTC (rev 70) +++ trunk/DAVInspector/src/de/dlr/davinspector/relay/ChannelThread.java 2008-03-04 13:07:57 UTC (rev 71) @@ -73,7 +73,7 @@ /** * */ - private boolean toClient = false; + private boolean myDirection; /** * The logger. @@ -124,22 +124,18 @@ try { InputStream in = myInputSocket.getInputStream(); -//# OutputStream out = outSock.getOutputStream(); try { count = in.read(buffer); while ((count != Constant.EOF) && !isInterrupted()) { -//# out.write(buf, 0, count); synchronized (myLock) { - myLock.updateData(new String(buffer, 0, count, "utf-8"), toClient); - myLock.notifyListeners(toClient); + // TODO: add encoding to configuration and set encoding from configuration + myLock.updateData(new String(buffer, 0, count, "utf-8"), myDirection); } count = in.read(buffer); } } catch (IOException ioe) { myLogger.error(myThreadName + COLON + ioe.getMessage(), ioe); } finally { - // The input and output streams will be closed when the sockets themselves are closed. -//# out.flush(); myLogger.info(myThreadName + COLON + "flushing"); flushOut(); } @@ -151,15 +147,14 @@ myDone = true; try { if ((myPeer == null) || myPeer.isDone()) { - // Cleanup if there is only one peer OR if _both_ peers are done + // if the peer is already closed or has transferred all data, shutdown myInputSocket.close(); myOutputSocket.close(); myLogger.info(myThreadName + COLON + "closing"); } else { - // Signal the peer (if any) that we're done on this side of the connection -// flushOut(); - myLogger.info(myThreadName + COLON + "interrupting peer"); + // signal the peer we are done myPeer.interrupt(); + myLogger.info(myThreadName + COLON + "interrupting peer"); } } catch (IOException ioe) { myLogger.error(myThreadName + COLON + ioe.getMessage(), ioe); @@ -175,10 +170,10 @@ * true = from server to client<br> * false = from client to server<br> * - * @param bToClient Boolean + * @param direction Boolean */ - public void setToClient(boolean bToClient) { - this.toClient = bToClient; + public void setDirection(boolean direction) { + this.myDirection = direction; } /** @@ -214,7 +209,7 @@ * * @param data String data to send. */ - public void writeOut(String data) { + public void write(String data) { try { OutputStream out = myOutputSocket.getOutputStream(); if (isChunked(data)) { @@ -258,7 +253,7 @@ * @return Boolean */ public Boolean getDirection() { - return toClient; + return myDirection; } /** @@ -269,6 +264,7 @@ */ private Boolean isChunked(String data) { // TODO: RFC 2616 14.39 TE / 14.41 Transfer-Encoding + // Output decorator!? Boolean result = false; if (data.contains("Transfer-Encoding: chunked")) { result = true; Modified: trunk/DAVInspector/src/de/dlr/davinspector/relay/IRelayModel.java =================================================================== --- trunk/DAVInspector/src/de/dlr/davinspector/relay/IRelayModel.java 2008-03-04 10:20:48 UTC (rev 70) +++ trunk/DAVInspector/src/de/dlr/davinspector/relay/IRelayModel.java 2008-03-04 13:07:57 UTC (rev 71) @@ -25,8 +25,11 @@ package de.dlr.davinspector.relay; +import org.apache.commons.logging.Log; + import de.dlr.davinspector.configuration.Configuration; import de.dlr.davinspector.history.MessageHistory; +import de.dlr.davinspector.plugin.PluginManager; /** @@ -50,20 +53,19 @@ /** * This method writes data to the client. - * INFO: Maybe Message instead of a string!? * @param data String */ void writeToClient(String data); /** * This method writes data to the server. - * INFO: Maybe {@link Message} instead of a string!? * @param data String */ void writeToServer(String data); /** - * This method adds the data to the string buffer for server or client depending on the <code>toClient</code> parameter. + * This method notifies the listeners for server or client depending on the <code>toClient</code> + * parameter and uses the <code>data</code> to create a new {@link DataEvent}. * * @param data String * @param toClient Boolean @@ -71,19 +73,26 @@ void updateData(String data, Boolean toClient); /** - * This method calls the notify methods for server or client depending on the <code>toClient</code> parameter. + * Returns the MessageHistory object. * - * @param toClient Boolean + * @return {@link MessageHistory} */ - void notifyListeners(Boolean toClient); + MessageHistory getMessageHistory(); /** - * Returns the MessageHistory object. + * Returns the PluginManager. * - * @return {@link MessageHistory} + * @return {@link PluginManager} */ - MessageHistory getMessageHistory(); + PluginManager getPluginManager(); + /** + * Returns Log object from Apache Commons Logging. + * + * @return Log + */ + Log getSystemLog(); + /** * Adds an {@link IServerListener} to RelayModel. * Modified: trunk/DAVInspector/src/de/dlr/davinspector/relay/RelayModel.java =================================================================== --- trunk/DAVInspector/src/de/dlr/davinspector/relay/RelayModel.java 2008-03-04 10:20:48 UTC (rev 70) +++ trunk/DAVInspector/src/de/dlr/davinspector/relay/RelayModel.java 2008-03-04 13:07:57 UTC (rev 71) @@ -42,7 +42,9 @@ import de.dlr.davinspector.common.Constant; import de.dlr.davinspector.configuration.Configuration; +import de.dlr.davinspector.configuration.PluginConfiguration; import de.dlr.davinspector.history.MessageHistory; +import de.dlr.davinspector.plugin.PluginManager; /** * Implementation of the relay interface. Provides the server socket @@ -85,21 +87,16 @@ private ServerSocket serverSocket; /** + * Plugin manager. + */ + private PluginManager myPluginManager = null; + + /** * The lock object is used for synchronizing the ChannelThreads. */ private Object lock = new Object(); /** - * Client side string buffer. - */ - private String clientBuffer; - - /** - * Server side string buffer. - */ - private String serverBuffer; - - /** * Contains all current connections (ChannelThreads). */ private List<ChannelThread> connections = new Vector<ChannelThread>(); @@ -107,24 +104,50 @@ /** * The message history object. */ - private MessageHistory messageHistory = null; + private MessageHistory myMessageHistory = null; /** * Constructor of RelayModel. * The constructor creates a new {@link MessageHistory} object. */ public RelayModel() { - messageHistory = new MessageHistory(this); + myMessageHistory = new MessageHistory(this); + myPluginManager = PluginManager.getInstance(); + // load available plugins + myPluginManager.loadAllPlugins(); + // load plugin configuration (if available) + PluginConfiguration pluginConfiguration = new PluginConfiguration(); + pluginConfiguration.loadConfiguration(); + myPluginManager.setActivePluginsClient(pluginConfiguration.getActivePluginsClient()); + myPluginManager.setActivePluginsServer(pluginConfiguration.getActivePluginsServer()); } /** * {@inheritDoc} * + * @see de.dlr.davinspector.relay.IRelayModel#getPluginManager() + */ + public PluginManager getPluginManager() { + return myPluginManager; + } + + /** + * {@inheritDoc} + * * @see de.dlr.davinspector.relay.IRelayModel#getMessageHistory() */ public MessageHistory getMessageHistory() { - return messageHistory; + return myMessageHistory; } + + /** + * {@inheritDoc} + * + * @see de.dlr.davinspector.relay.IRelayModel#getSystemLog() + */ + public Log getSystemLog() { + return myLogger; + } /** * {@inheritDoc} @@ -201,6 +224,7 @@ } else { serverSocket = new ServerSocket(configuration.getClientPort(), Constant.RELAY_BACKLOG, clientAddress); } + serverSocket.setReuseAddress(true); myDestinationAddress = serverAddress; myDestinationPort = configuration.getServerPort(); } catch (UnknownHostException uhe) { @@ -222,8 +246,6 @@ while (!isInterrupted()) { Socket serverSideSocket = serverSocket.accept(); try { - clientBuffer = ""; - serverBuffer = ""; serverSideSocket.setSoLinger(true, Constant.RELAY_LINGERTIME); Socket clientSideSocket = new Socket(myDestinationAddress, myDestinationPort); clientSideSocket.setSoLinger(true, Constant.RELAY_LINGERTIME); @@ -233,8 +255,8 @@ (IRelayModel) this, myLogger, connections); serverToClientChannel.setPeer(clientToServerChannel); clientToServerChannel.setPeer(serverToClientChannel); - serverToClientChannel.setToClient(true); - clientToServerChannel.setToClient(false); + serverToClientChannel.setDirection(true); + clientToServerChannel.setDirection(false); serverToClientChannel.setTName("ServerToClientThread"); clientToServerChannel.setTName("ClientToServerThread"); synchronized (lock) { @@ -292,16 +314,15 @@ } /** - * TODO: Enter comment! Not quite correct ... + * TODO: Not quite correct ... * - * * @param data String * @param toClient Boolean */ private void write(String data, Boolean toClient) { for (ChannelThread connection : connections) { if (connection.getDirection() != toClient) { - connection.writeOut(data); + connection.write(data); } } } @@ -332,22 +353,9 @@ */ public void updateData(String data, Boolean toClient) { if (toClient) { - clientBuffer += data; + notifyClientListeners(new DataEvent(this, data)); } else { - serverBuffer += data; + notifyServerListeners(new DataEvent(this, data)); } } - - /** - * {@inheritDoc} - * - * @see de.dlr.DAVInspector.Relay.IRelayModel#notifyListeners(java.lang.Boolean) - */ - public void notifyListeners(Boolean toClient) { - if (toClient) { - notifyClientListeners(new DataEvent(this, clientBuffer)); - } else { - notifyServerListeners(new DataEvent(this, serverBuffer)); - } - } } Modified: trunk/DAVInspector/src/de/dlr/davinspector/ui/MainView.java =================================================================== --- trunk/DAVInspector/src/de/dlr/davinspector/ui/MainView.java 2008-03-04 10:20:48 UTC (rev 70) +++ trunk/DAVInspector/src/de/dlr/davinspector/ui/MainView.java 2008-03-04 13:07:57 UTC (rev 71) @@ -517,8 +517,7 @@ myRelay.getMessageHistory().addNewMessageListener(this); myRelay.getMessageHistory().addRefreshMessageListener(this); - myPluginManager = PluginManager.getInstance(); - myPluginManager.loadAllPlugins(); + myPluginManager = myRelay.getPluginManager(); jFrame = getJFrame(); jFrame.pack(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |