1 /*** 2 * 3 * Copyright 2004 Protique Ltd 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 **/ 18 package org.codehaus.activemq.transport.ember; 19 20 import org.codehaus.activemq.message.WireFormat; 21 import org.codehaus.activemq.transport.TransportServerChannel; 22 import org.codehaus.activemq.transport.TransportServerChannelFactory; 23 import pyrasun.eio.EIOGlobalContext; 24 import pyrasun.eio.EIOPoolingStrategy; 25 import pyrasun.eio.services.EmberServiceController; 26 import pyrasun.eio.services.bytearray.ByteArrayServerService; 27 28 import javax.jms.JMSException; 29 import java.io.IOException; 30 import java.net.URI; 31 32 /*** 33 * An EmberIO (using NIO) implementation of a TransportServerChannelFactory 34 * 35 * @version $Revision: 1.7 $ 36 */ 37 public class EmberTransportServerChannelFactory extends EmberSupport implements TransportServerChannelFactory { 38 39 private EIOPoolingStrategy acceptPoolingStrategy; 40 private String acceptPoolingStrategyName = "BLOCKING_ACCEPTOR"; 41 42 public EmberTransportServerChannelFactory() { 43 } 44 45 public EmberTransportServerChannelFactory(EIOGlobalContext context, EIOPoolingStrategy ioPoolingStrategy, EIOPoolingStrategy acceptPoolingStrategy) { 46 super(context, ioPoolingStrategy); 47 this.acceptPoolingStrategy = acceptPoolingStrategy; 48 } 49 50 /*** 51 * Bind a ServerChannel to an address 52 * 53 * @param wireFormat 54 * @param bindAddress 55 * @return the TransportChannel bound to the remote node 56 * @throws JMSException 57 */ 58 public TransportServerChannel create(WireFormat wireFormat, URI bindAddress) throws JMSException { 59 try { 60 EmberServiceController controller = getController(); 61 ByteArrayServerService service = new ByteArrayServerService(getContext(), getAcceptPoolingStrategy(), getIoPoolingStrategy(), bindAddress.getHost(), bindAddress.getPort()); 62 controller.addService(service); 63 64 EmberTransportServerChannel answer = new EmberTransportServerChannel(wireFormat, bindAddress, getContext(), controller); 65 service.setListener(answer); 66 return answer; 67 } 68 catch (IOException e) { 69 throw createJMSException("Initialization of TransportServerChannel failed: ", e); 70 } 71 } 72 73 protected EIOPoolingStrategy getAcceptPoolingStrategy() { 74 if (acceptPoolingStrategy == null) { 75 acceptPoolingStrategy = getPoolingStrategyByName(acceptPoolingStrategyName); 76 } 77 return acceptPoolingStrategy; 78 } 79 }