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.http;
023:
024: import java.io.Serializable;
025:
026: import org.jboss.logging.Logger;
027: import org.jboss.mq.ReceiveRequest;
028: import org.jboss.mq.SpyDestination;
029: import org.jboss.mq.il.ClientIL;
030:
031: /**
032: * The HTTP/S implementation of the ClientIL object
033: *
034: * @author Nathan Phelps (nathan@jboss.org)
035: * @version $Revision: 57198 $
036: * @created January 15, 2003
037: */
038: public class HTTPClientIL implements ClientIL, Serializable {
039: static final long serialVersionUID = 3215139925343217398L;
040: public boolean stopped = true;
041:
042: private static Logger log = Logger.getLogger(HTTPClientIL.class);
043: private String clientIlId = null;
044:
045: public HTTPClientIL(String clientIlId) {
046: this .clientIlId = clientIlId;
047: if (log.isTraceEnabled()) {
048: log.trace("created(" + clientIlId + ")");
049: }
050: }
051:
052: public void close() throws Exception {
053: if (log.isTraceEnabled()) {
054: log.trace("close()");
055: }
056: this .throwIllegalStateExceptionIfStopped();
057: HTTPILRequest request = new HTTPILRequest();
058: request.setMethodName("asynchClose");
059: HTTPClientILStorageQueue.getInstance().put(request,
060: this .clientIlId);
061: }
062:
063: public void deleteTemporaryDestination(SpyDestination dest)
064: throws Exception {
065: if (log.isTraceEnabled()) {
066: log.trace("deleteTemporaryDestination(SpyDestination "
067: + dest.toString() + ")");
068: }
069: this .throwIllegalStateExceptionIfStopped();
070: HTTPILRequest request = new HTTPILRequest();
071: request.setMethodName("asynchDeleteTemporaryDestination");
072: request.setArguments(new Object[] { dest },
073: new Class[] { SpyDestination.class });
074: HTTPClientILStorageQueue.getInstance().put(request,
075: this .clientIlId);
076: }
077:
078: public void pong(long serverTime) throws Exception {
079: this .throwIllegalStateExceptionIfStopped();
080: HTTPILRequest request = new HTTPILRequest();
081: request.setMethodName("asynchPong");
082: request.setArguments(new Object[] { new Long(serverTime) },
083: new Class[] { long.class });
084: HTTPClientILStorageQueue.getInstance().put(request,
085: this .clientIlId);
086: }
087:
088: public void receive(ReceiveRequest[] messages) throws Exception {
089: if (log.isTraceEnabled()) {
090: log.trace("receive(ReceiveRequest[] arraylength="
091: + String.valueOf(messages.length) + ")");
092: }
093: this .throwIllegalStateExceptionIfStopped();
094: HTTPILRequest request = new HTTPILRequest();
095: request.setMethodName("asynchDeliver");
096: request.setArguments(new Object[] { messages },
097: new Class[] { ReceiveRequest[].class });
098: HTTPClientILStorageQueue.getInstance().put(request,
099: this .clientIlId);
100: }
101:
102: private void throwIllegalStateExceptionIfStopped()
103: throws IllegalStateException {
104: if (this .stopped) {
105: throw new IllegalStateException("The client IL is stopped.");
106: }
107: }
108:
109: }
|