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: import java.rmi.RemoteException;
026:
027: import org.jboss.mq.Connection;
028: import org.jboss.mq.ReceiveRequest;
029: import org.jboss.mq.SpyDestination;
030:
031: /**
032: * The OIL2 implementation of the ClientILService object
033: *
034: * @author <a href="mailto:hiram.chirino@jboss.org">Hiram Chirino</a>
035: * @version $Revision: $
036: */
037: public final class OIL2ClientILService implements
038: org.jboss.mq.il.ClientILService, OIL2RequestListner {
039: //A link on my connection
040: private Connection connection;
041:
042: // The OIL2Server that created the socketHandler
043: OIL2ServerIL serverIL;
044:
045: // The SocketHandler we will be sharing with the ServerIL
046: OIL2SocketHandler socketHandler;
047:
048: /**
049: * getClientIL method comment.
050: *
051: * @return The ClientIL value
052: * @exception java.lang.Exception Description of Exception
053: */
054: public org.jboss.mq.il.ClientIL getClientIL()
055: throws java.lang.Exception {
056: return new OIL2ClientIL();
057: }
058:
059: /**
060: * init method comment.
061: *
062: * @param connection Description of Parameter
063: * @param props Description of Parameter
064: * @exception java.lang.Exception Description of Exception
065: */
066: public void init(org.jboss.mq.Connection connection,
067: java.util.Properties props) throws java.lang.Exception {
068: this .connection = connection;
069:
070: }
071:
072: /**
073: * start method comment.
074: *
075: * @exception java.lang.Exception Description of Exception
076: */
077: public void start() throws java.lang.Exception {
078: serverIL = (OIL2ServerIL) connection.getServerIL();
079: socketHandler = serverIL.socketHandler;
080: socketHandler.setRequestListner(this );
081: }
082:
083: /**
084: * @exception java.lang.Exception Description of Exception
085: */
086: public void stop() throws java.lang.Exception {
087: }
088:
089: public void handleConnectionException(Exception e) {
090: connection.asynchFailure("Connection failure", e);
091: serverIL.close();
092: }
093:
094: public void handleRequest(OIL2Request request) {
095: Object result = null;
096: Exception resultException = null;
097:
098: // now based upon the input directive, preform the
099: // requested action. Any exceptions are processed
100: // and potentially returned to the client.
101: //
102: try {
103: switch (request.operation) {
104: case OIL2Constants.CLIENT_RECEIVE:
105: connection
106: .asynchDeliver((ReceiveRequest[]) request.arguments[0]);
107: break;
108: case OIL2Constants.CLIENT_DELETE_TEMPORARY_DESTINATION:
109: connection
110: .asynchDeleteTemporaryDestination((SpyDestination) request.arguments[0]);
111: break;
112:
113: case OIL2Constants.CLIENT_CLOSE:
114: connection.asynchClose();
115: break;
116:
117: case OIL2Constants.CLIENT_PONG:
118: connection.asynchPong(((Long) request.arguments[0])
119: .longValue());
120: break;
121: default:
122: throw new RemoteException("Bad method code !");
123: } // switch
124: } catch (Exception e) {
125: resultException = e;
126: } // try
127:
128: try {
129: OIL2Response response = new OIL2Response(request);
130: response.result = result;
131: response.exception = resultException;
132: socketHandler.sendResponse(response);
133: } catch (IOException e) {
134: handleConnectionException(e);
135: }
136:
137: }
138:
139: }
140: // vim:expandtab:tabstop=3:shiftwidth=3
|