KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > mq > il > oil2 > OIL2ClientILService


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.mq.il.oil2;
8
9 import java.io.IOException JavaDoc;
10 import java.rmi.RemoteException JavaDoc;
11
12 import org.jboss.mq.Connection;
13 import org.jboss.mq.ReceiveRequest;
14 import org.jboss.mq.SpyDestination;
15
16 /**
17  * The OIL2 implementation of the ClientILService object
18  *
19  * @author <a HREF="mailto:hiram.chirino@jboss.org">Hiram Chirino</a>
20  * @version $Revision: $
21  */

22 public final class OIL2ClientILService
23    implements org.jboss.mq.il.ClientILService, OIL2RequestListner
24 {
25    //A link on my connection
26
private Connection connection;
27
28    // The OIL2Server that created the socketHandler
29
OIL2ServerIL serverIL;
30
31    // The SocketHandler we will be sharing with the ServerIL
32
OIL2SocketHandler socketHandler;
33
34    /**
35     * getClientIL method comment.
36     *
37     * @return The ClientIL value
38     * @exception java.lang.Exception Description of Exception
39     */

40    public org.jboss.mq.il.ClientIL getClientIL() throws java.lang.Exception JavaDoc
41    {
42       return new OIL2ClientIL();
43    }
44
45    /**
46     * init method comment.
47     *
48     * @param connection Description of Parameter
49     * @param props Description of Parameter
50     * @exception java.lang.Exception Description of Exception
51     */

52    public void init(org.jboss.mq.Connection connection, java.util.Properties JavaDoc props) throws java.lang.Exception JavaDoc
53    {
54       this.connection = connection;
55
56    }
57
58    /**
59     * start method comment.
60     *
61     * @exception java.lang.Exception Description of Exception
62     */

63    public void start() throws java.lang.Exception JavaDoc
64    {
65       serverIL = (OIL2ServerIL) connection.getServerIL();
66       socketHandler = serverIL.socketHandler;
67       socketHandler.setRequestListner(this);
68    }
69
70    /**
71     * @exception java.lang.Exception Description of Exception
72     */

73    public void stop() throws java.lang.Exception JavaDoc
74    {
75    }
76
77    public void handleConnectionException(Exception JavaDoc e)
78    {
79       connection.asynchFailure("Connection failure", e);
80       serverIL.close();
81    }
82
83    public void handleRequest(OIL2Request request)
84    {
85       Object JavaDoc result = null;
86       Exception JavaDoc resultException = null;
87
88       // now based upon the input directive, preform the
89
// requested action. Any exceptions are processed
90
// and potentially returned to the client.
91
//
92
try
93       {
94          switch (request.operation)
95          {
96             case OIL2Constants.CLIENT_RECEIVE :
97                connection.asynchDeliver((ReceiveRequest[]) request.arguments[0]);
98                break;
99             case OIL2Constants.CLIENT_DELETE_TEMPORARY_DESTINATION :
100                connection.asynchDeleteTemporaryDestination((SpyDestination) request.arguments[0]);
101                break;
102
103             case OIL2Constants.CLIENT_CLOSE :
104                connection.asynchClose();
105                break;
106
107             case OIL2Constants.CLIENT_PONG :
108                connection.asynchPong(((Long JavaDoc) request.arguments[0]).longValue());
109                break;
110             default :
111                throw new RemoteException JavaDoc("Bad method code !");
112          } // switch
113
}
114       catch (Exception JavaDoc e)
115       {
116          resultException = e;
117       } // try
118

119       try
120       {
121          OIL2Response response = new OIL2Response(request);
122          response.result = result;
123          response.exception = resultException;
124          socketHandler.sendResponse(response);
125       }
126       catch (IOException JavaDoc e)
127       {
128          handleConnectionException(e);
129       }
130
131    }
132
133 }
134 // vim:expandtab:tabstop=3:shiftwidth=3
135
Popular Tags