communicationhandler.java
来自「主要是对串口驱动的的一些控制源码!!! 在下载javacomm20-win32」· Java 代码 · 共 200 行
JAVA
200 行
/**
* $Log: CommunicationHandler.java,v $
* Revision 1.2 2003/02/03 13:03:35 mwulff
* now calls streamWrapper.closeConnection() in followUpConnection()
*
* Revision 1.1 2003/01/16 13:12:40 mwulff
* initial version
*
* Revision 1.6 2002/12/20 18:52:25 mwulff
* no message
*
* Revision 1.5 2002/12/15 16:55:07 mwulff
* adjusted to reorganisation of the client logging system
*
* Revision 1.4 2002/12/13 20:08:35 mwulff
* no message
*
* Revision 1.3 2002/12/05 21:33:50 mwulff
* reengineering of the complete communication component
*
* Revision 1.2 2002/12/01 13:02:14 mwulff
* accomodated to ClientResourceManager and ClientLoggingManager,
* that are now implemented as singleton
*
* Revision 1.1 2002/11/22 16:42:45 mwulff
* moved
*
* Revision 1.2 2002/11/08 19:23:04 mwulff
* updated to handle remote garbage collection
*
* Revision 1.1 2002/11/05 19:46:51 mwulff
* initial version
*
*/
package de.fhm.jkf.comm.cl;
import java.io.IOException;
import java.net.URL;
import java.util.Vector;
import de.fhm.jkf.comm.clsv.CompressionHandler;
import de.fhm.jkf.comm.clsv.Request;
import de.fhm.jkf.comm.clsv.Response;
import de.fhm.jkf.comm.clsv.ResponseCommands;
import de.fhm.jkf.resource.cl.ClientResourceManager;
/**
* <br><br><center><table border="1" width="80%"><hr>
* <strong><a href="http://jkf.sourceforge.net">The JKF Project</a></strong>
* <p>
* Copyright (C) 2002 by Marten Wulff
* <p>
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* <p>
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* <p>
* You should have received a copy of the <a href="http://www.gnu.org/copyleft/lesser.html">
* GNU Lesser General Public License</a> along with this library; if not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
* <hr></table></center>
*
*
* <p>
* <code>CommunicationHandler</code> is the abstract parent class of
* all client side classes, that communicate with the server. This class
* is responsible for handling the client side connection to the server.
* Therefore is used a <code>URLConnection</code>. Also handling of client
* logging messages, that should be transfered to the server, and remote
* garbage collection is done by this class.
* If any <code>ResponseCommands</code> are received from the server, they
* are delegated to the <code>ClientResourceManager</code>.
* </p>
*
* @see java.net.URLConnection
* @see de.fhm.jkf.resource.cl.ClientResourceManager
*
* @author marten wulff
* @version 1.0
*/
abstract class CommunicationHandler {
// reference to the singlton RemoteLogBuffer
protected static RemoteLogBuffer logBuffer = RemoteLogBuffer.instance();
// reference to the singleton RemoteGCBuffer
protected static RemoteGCBuffer gcBuffer = RemoteGCBuffer.instance();
// Reference to the ClientResourceManger
protected static ClientResourceManager resManager =
ClientResourceManager.instance();
// Reference to the SessionManager
protected static SessionManager sessionManager = SessionManager.instance();
// URL for the RequestBrokerServlet
protected URL requestBrokerServlet = null;
// CompressionHandler that is used to enable compressed data transer
protected CompressionHandler compressionHandler = null;
protected URLConnectionStreamWrapper wrapper = null;
/**
* Constructor for CommunicationHandler.
*/
CommunicationHandler() {
super();
requestBrokerServlet = resManager.getRequestBrokerURL();
compressionHandler =
new ClientCompressionHandler(
resManager.getCompressLimit(),
resManager.getCommunicationBufferSize());
}
/**
* Method for adding available log messages to the client
* request. All LoggingEvents stored in the RemoteLogBuffer
* are retrieved and added to the request.
*
* @param request the Request which is send to the server
*/
void handleLogMessages(Request request) {
// let's see if there are any log messages we can send
// to the server
Vector logs = logBuffer.getLogMessages();
if (logs.size() > 0) {
request.setLogMessages(logs);
}
}
/**
* Method for adding available gc messages to the client
* request.
*
* @param request the Request which will be send to the server
*/
void handleGCMessages(Request request) {
// let's see if there are any remote objects that
// should be handled by the remote garbage collection
Vector gcObjects = gcBuffer.getGCMessages();
if (gcObjects.size() > 0) {
request.setGCMessages(gcObjects);
}
}
/**
* Method for openning a connection to the server. Thereby is
* handled transferation of client logging events and remote garbage
* collection.
*
* @param request the Request that is send to the server
*
* @see de.fhm.jkf.comm.clsv.Request
*
* @throws IOException if any I/O-Error occures
*/
void prepareConnection(Request request) throws IOException {
// let's see if there are any log messages we can send
// to the server
handleLogMessages(request);
// are there any objects for the remote garbage collection ??
handleGCMessages(request);
wrapper =
new URLConnectionStreamWrapper(
this.requestBrokerServlet.openConnection());
wrapper.setSessionInfo(sessionManager.getSessionInfo());
compressionHandler.setStreamWrapper(wrapper);
}
/**
* This method does all the work, that has to be done after a
* server request. Right at the moment there is only a check
* if the server transfered some <code>ResponseCommands</code>.
* If available the <code>ResponseCommands</code> are delegated
* to the <code>ClientResourceManager</code>.
*
* @param response the response from the last server connection
*/
void followUpConnection(Response response) {
ResponseCommands commands = response.getResponseCommands();
if (commands != null) {
resManager.interpretResponseCommands(commands);
}
wrapper.closeConnection();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?