/** 
 * 
 * Copyright 2004 Protique Ltd
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 * 
 **/
package org.activemq.transport.http;

import EDU.oswego.cs.dl.util.concurrent.Channel;
import org.activemq.message.Packet;
import org.activemq.transport.TransportChannelSupport;
import org.activemq.util.JMSExceptionHelper;

import javax.jms.JMSException;

/**
 * A server side HTTP based TransportChannel which processes incoming packets
 * and adds outgoing packets onto a {@link Channel} so that they can be dispatched
 * by the HTTP GET requests from the client.
 *
 * @version $Revision$
 */
public class HttpServerTransportChannel extends TransportChannelSupport {
    private Channel channel;

    public HttpServerTransportChannel(Channel channel) {
        this.channel = channel;
    }

    public Channel getChannel() {
        return channel;
    }

    public void start() throws JMSException {
    }

    public void asyncSend(Packet packet) throws JMSException {
        // lets queue up the request waiting for it to be requested
        // using a HTTP GET
        try {
            channel.put(packet);
        }
        catch (InterruptedException e) {
            throw JMSExceptionHelper.newJMSException("Failed to send: " + packet + ". Reason: " + e, e);
        }
    }

    public boolean isMulticast() {
        return false;
    }
    
    /**
     * Can this wireformat process packets of this version
     * @param version the version number to test
     * @return true if can accept the version
     */
    public boolean canProcessWireFormatVersion(int version){
        return true;
    }
    
    /**
     * @return the current version of this wire format
     */
    public int getCurrentWireFormatVersion(){
        return 1;
    }
    
	public void forceDisconnect() {
	    // TODO: implement me.
		throw new RuntimeException("Not yet Implemented.");
	}
}
