Home » synapse-1.2-src » org.apache.synapse.transport.fix » [javadoc | source]

    1   /*
    2    *  Licensed to the Apache Software Foundation (ASF) under one
    3    *  or more contributor license agreements.  See the NOTICE file
    4    *  distributed with this work for additional information
    5    *  regarding copyright ownership.  The ASF licenses this file
    6    *  to you under the Apache License, Version 2.0 (the
    7    *  "License"); you may not use this file except in compliance
    8    *  with the License.  You may obtain a copy of the License at
    9    *
   10    *   http://www.apache.org/licenses/LICENSE-2.0
   11    *
   12    *  Unless required by applicable law or agreed to in writing,
   13    *  software distributed under the License is distributed on an
   14    *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   15    *  KIND, either express or implied.  See the License for the
   16    *  specific language governing permissions and limitations
   17    *  under the License.
   18    */
   19   
   20   package org.apache.synapse.transport.fix;
   21   
   22   import org.apache.axis2.AxisFault;
   23   import org.apache.axis2.addressing.EndpointReference;
   24   import org.apache.axis2.context.ConfigurationContext;
   25   import org.apache.axis2.description.AxisService;
   26   import org.apache.axis2.description.TransportInDescription;
   27   import org.apache.synapse.transport.base.AbstractTransportListener;
   28   import org.apache.synapse.transport.base.ManagementSupport;
   29   
   30   /**
   31    * The FIX transport listener implementation. A FIX Transport Listner will hold
   32    * a FIX session factory, which would be created at initialization
   33    * time. This implementation supports the creation of FIX sessions at runtime
   34    * as and when required. This FIX Listener registers with Axis to be notified
   35    * of service deployment/undeployment/start/stop, and enables or disables
   36    * listening for FIX messages on the destinations as appropriate.
   37    * <p/>
   38    * Service must state where the FIX configuration file is located so
   39    * that  the required FIX sessions can be initialized for the service.
   40    * FIX configuration file should be a valid Quickfix/J session
   41    * configuration file. A URL to the file should be provided.
   42    * <p/>
   43    * <parameter name="transport.fix.AcceptorConfigURL">
   44    * http://www.mycompany.org/fixconfig/file.cfg</parameter>
   45    */
   46   public class FIXTransportListener extends AbstractTransportListener {
   47   
   48       /**
   49        * The FIXSessionFactory takes care of creating and managing all the
   50        * FIX sessions.
   51        */
   52       private FIXSessionFactory fixSessionFactory;
   53   
   54       /**
   55        * This is the TransportListener initialization method invoked by Axis2
   56        *
   57        * @param cfgCtx    the Axis configuration context
   58        * @param trpInDesc the TransportIn description
   59        */
   60       public void init(ConfigurationContext cfgCtx,
   61                        TransportInDescription trpInDesc) throws AxisFault {
   62   
   63           setTransportName(FIXConstants.TRANSPORT_NAME);
   64           super.init(cfgCtx, trpInDesc);
   65           //initialize the FIXSessionFactory
   66           fixSessionFactory = new FIXSessionFactory(new FIXApplicationFactory(this.cfgCtx, this.workerPool));
   67           FIXTransportSender sender = (FIXTransportSender) cfgCtx.
   68                   getAxisConfiguration().getTransportOut(FIXConstants.TRANSPORT_NAME).getSender();
   69           sender.setSessionFactory(fixSessionFactory);
   70           log.info("FIX transport listener initialized...");
   71       }
   72   
   73       /**
   74        * Prepare to listen for FIX messages on behalf of the given service
   75        * by first creating and starting a FIX session
   76        *
   77        * @param service the service for which to listen for messages
   78        */
   79       protected void startListeningForService(AxisService service) {
   80   
   81           if (service.getName().startsWith("__")) {
   82               return;
   83           }
   84           
   85           fixSessionFactory.createFIXAcceptor(service);
   86       }
   87   
   88       /**
   89        * Stops listening for messages for the service thats undeployed or stopped
   90        * by stopping and disposing the appropriate FIX session
   91        *
   92        * @param service the service that was undeployed or stopped
   93        */
   94       protected void stopListeningForService(AxisService service) {
   95           fixSessionFactory.disposeFIXAcceptor(service);
   96       }
   97   
   98       /**
   99        * Returns EPRs for the given service and IP over the FIX transport
  100        *
  101        * @param serviceName service name
  102        * @param ip          ignored
  103        * @return the EPR for the service
  104        * @throws AxisFault
  105        */
  106       public EndpointReference[] getEPRsForService(String serviceName, String ip) throws AxisFault {
  107           //Try to get the list of EPRs from the FIXSessionFactory
  108           String[] serviceEPRStrings = fixSessionFactory.getServiceEPRs(serviceName, ip);
  109           if (serviceEPRStrings != null) {
  110               EndpointReference[] serviceEPRs = new EndpointReference[serviceEPRStrings.length];
  111               for (int i = 0; i < serviceEPRStrings.length; i++) {
  112                   serviceEPRs[i] = new EndpointReference(serviceEPRStrings[i]);
  113               }
  114               return serviceEPRs;
  115           }
  116           throw new AxisFault("Unable to get EPRs for the service " + serviceName);
  117       }
  118   }

Home » synapse-1.2-src » org.apache.synapse.transport.fix » [javadoc | source]