KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > mq > il > http > HTTPClientIL


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.mq.il.http;
23
24 import java.io.Serializable JavaDoc;
25
26 import org.jboss.logging.Logger;
27 import org.jboss.mq.ReceiveRequest;
28 import org.jboss.mq.SpyDestination;
29 import org.jboss.mq.il.ClientIL;
30
31 /**
32  * The HTTP/S implementation of the ClientIL object
33  *
34  * @author Nathan Phelps (nathan@jboss.org)
35  * @version $Revision: 37459 $
36  * @created January 15, 2003
37  */

38 public class HTTPClientIL implements ClientIL, Serializable JavaDoc
39 {
40    static final long serialVersionUID = 3215139925343217398L;
41     public boolean stopped = true;
42     
43     private static Logger log = Logger.getLogger(HTTPClientIL.class);
44     private String JavaDoc clientIlId = null;
45     
46     public HTTPClientIL(String JavaDoc clientIlId)
47     {
48         this.clientIlId = clientIlId;
49         if (log.isTraceEnabled())
50         {
51             log.trace("created(" + clientIlId + ")");
52         }
53     }
54     
55     public void close() throws Exception JavaDoc
56     {
57         if (log.isTraceEnabled())
58         {
59             log.trace("close()");
60         }
61         this.throwIllegalStateExceptionIfStopped();
62         HTTPILRequest request = new HTTPILRequest();
63         request.setMethodName("asynchClose");
64         HTTPClientILStorageQueue.getInstance().put(request, this.clientIlId);
65     }
66     
67     public void deleteTemporaryDestination(SpyDestination dest) throws Exception JavaDoc
68     {
69         if (log.isTraceEnabled())
70         {
71             log.trace("deleteTemporaryDestination(SpyDestination " + dest.toString() + ")");
72         }
73         this.throwIllegalStateExceptionIfStopped();
74         HTTPILRequest request = new HTTPILRequest();
75         request.setMethodName("asynchDeleteTemporaryDestination");
76         request.setArguments(new Object JavaDoc[]
77         {dest}, new Class JavaDoc[]
78         {SpyDestination.class});
79         HTTPClientILStorageQueue.getInstance().put(request, this.clientIlId);
80     }
81     
82     public void pong(long serverTime) throws Exception JavaDoc
83     {
84         this.throwIllegalStateExceptionIfStopped();
85         HTTPILRequest request = new HTTPILRequest();
86         request.setMethodName("asynchPong");
87         request.setArguments(new Object JavaDoc[]
88         {new Long JavaDoc(serverTime)}, new Class JavaDoc[]
89         {long.class});
90         HTTPClientILStorageQueue.getInstance().put(request, this.clientIlId);
91     }
92     
93     public void receive(ReceiveRequest[] messages) throws Exception JavaDoc
94     {
95         if (log.isTraceEnabled())
96         {
97             log.trace("receive(ReceiveRequest[] arraylength=" + String.valueOf(messages.length) + ")");
98         }
99         this.throwIllegalStateExceptionIfStopped();
100         HTTPILRequest request = new HTTPILRequest();
101         request.setMethodName("asynchDeliver");
102         request.setArguments(new Object JavaDoc[]
103         {messages}, new Class JavaDoc[]
104         {ReceiveRequest[].class});
105         HTTPClientILStorageQueue.getInstance().put(request, this.clientIlId);
106     }
107     
108     private void throwIllegalStateExceptionIfStopped() throws IllegalStateException JavaDoc
109     {
110         if (this.stopped)
111         {
112             throw new IllegalStateException JavaDoc("The client IL is stopped.");
113         }
114     }
115     
116 }
Popular Tags