001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.mq.il.oil2;
023:
024: import java.io.IOException;
025:
026: import org.jboss.mq.ReceiveRequest;
027: import org.jboss.mq.SpyDestination;
028: import org.jboss.mq.il.ClientIL;
029:
030: /**
031: * The OIL2 implementation of the ClientIL object
032: *
033: * @author <a href="mailto:hiram.chirino@jboss.org">Hiram Chirino</a>
034: * @version $Revision:$
035: */
036: public final class OIL2ClientIL implements ClientIL,
037: java.io.Serializable {
038: static final long serialVersionUID = -2671278802714517625L;
039: transient OIL2ServerILService.RequestListner requestListner;
040: transient OIL2SocketHandler socketHandler;
041:
042: public void setRequestListner(
043: OIL2ServerILService.RequestListner requestListner) {
044: this .requestListner = requestListner;
045: this .socketHandler = requestListner.getSocketHandler();
046: }
047:
048: /**
049: * #Description of the Method
050: *
051: * @exception Exception Description of Exception
052: */
053: public void close() throws Exception {
054: try {
055:
056: OIL2Request request = new OIL2Request(
057: OIL2Constants.CLIENT_CLOSE, null);
058: OIL2Response response = socketHandler.synchRequest(request);
059: response.evalThrowsException();
060:
061: } catch (IOException ignore) {
062: // Server closes the socket before we get a response..
063: // this is ok.
064: }
065:
066: // The close request now went full cycle, from the client
067: // to the server, and back from the server to the client.
068: // Close up the requestListner
069: // This will shut down the sockets and threads.
070: requestListner.close();
071: }
072:
073: /**
074: * #Description of the Method
075: *
076: * @param dest Description of Parameter
077: * @exception Exception Description of Exception
078: */
079: public void deleteTemporaryDestination(SpyDestination dest)
080: throws Exception {
081:
082: OIL2Request request = new OIL2Request(
083: OIL2Constants.CLIENT_DELETE_TEMPORARY_DESTINATION,
084: new Object[] { dest });
085: OIL2Response response = socketHandler.synchRequest(request);
086: response.evalThrowsException();
087: }
088:
089: /**
090: * #Description of the Method
091: *
092: * @param serverTime Description of Parameter
093: * @exception Exception Description of Exception
094: */
095: public void pong(long serverTime) throws Exception {
096: OIL2Request request = new OIL2Request(
097: OIL2Constants.CLIENT_PONG, new Object[] { new Long(
098: serverTime) });
099: OIL2Response response = socketHandler.synchRequest(request);
100: response.evalThrowsException();
101: }
102:
103: /**
104: * #Description of the Method
105: *
106: * @param messages Description of Parameter
107: * @exception Exception Description of Exception
108: */
109: public void receive(ReceiveRequest messages[]) throws Exception {
110:
111: OIL2Request request = new OIL2Request(
112: OIL2Constants.CLIENT_RECEIVE, new Object[] { messages });
113: OIL2Response response = socketHandler.synchRequest(request);
114: response.evalThrowsException();
115: }
116:
117: }
118: // vim:expandtab:tabstop=3:shiftwidth=3
|