001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.activemq.transport; 018 019import java.util.Map; 020 021import org.apache.activemq.util.IntrospectionSupport; 022import org.eclipse.jetty.server.Connector; 023import org.eclipse.jetty.server.Server; 024 025public class SocketConnectorFactory { 026 027 private Map<String, Object> transportOptions; 028 029 public Connector createConnector(Server server) throws Exception { 030 Connector connector = null; 031 032 try { 033 connector = (Connector)Class.forName("org.eclipse.jetty.server.nio.SelectChannelConnector", true, Server.class.getClassLoader()).newInstance(); 034 } catch (Throwable t) { 035 Class<?> c = Class.forName("org.eclipse.jetty.server.ServerConnector", true, Server.class.getClassLoader()); 036 connector = (Connector)c.getConstructor(Server.class).newInstance(server); 037 Server.class.getMethod("setStopTimeout", Long.TYPE).invoke(server, 500); 038 connector.getClass().getMethod("setStopTimeout", Long.TYPE).invoke(connector, 500); 039 } 040 System.out.println(transportOptions); 041 if (transportOptions != null) { 042 IntrospectionSupport.setProperties(connector, transportOptions, ""); 043 } 044 return connector; 045 } 046 047 public Map<String, Object> getTransportOptions() { 048 return transportOptions; 049 } 050 051 public void setTransportOptions(Map<String, Object> transportOptions) { 052 this.transportOptions = transportOptions; 053 } 054}