Example #1
0
  private void initServer() throws ConfigurationException {
    if (port == 0) {
      throw new ConfigurationException("Port value not set");
    }
    newChannel();
    if (channel == null) {
      throw new ConfigurationException("ISO Channel is null");
    }

    if (!(channel instanceof ServerChannel)) {
      throw new ConfigurationException(channelString + "does not implement ServerChannel");
    }

    ThreadPool pool = null;
    pool = new ThreadPool(minSessions, maxSessions);
    pool.setLogger(log.getLogger(), getName() + ".pool");

    server = new ISOServer(port, (ServerChannel) channel, pool);
    server.setLogger(log.getLogger(), getName() + ".server");
    server.setName(getName());
    if (socketFactoryString != null) {
      ISOServerSocketFactory sFac =
          (ISOServerSocketFactory) getFactory().newInstance(socketFactoryString);
      if (sFac != null && sFac instanceof LogSource) {
        ((LogSource) sFac).setLogger(log.getLogger(), getName() + ".socket-factory");
      }
      server.setSocketFactory(sFac);
    }
    getFactory().setConfiguration(server, getPersist());
    addServerSocketFactory();
    addListeners(); // ISORequestListener
    addISOServerConnectionListeners();
    NameRegistrar.register(getName(), this);
    new Thread(server).start();
  }
Example #2
0
  public static void main(String[] args) throws Exception {
    XMLChannel clientSide = new XMLChannel(new XMLPackager());
    // without a logger on the channel we don't see send and receive only session-start and -end
    Logger logger = Common.logger("server");
    clientSide.setLogger(logger, "server");

    String pid = getPid();
    System.out.println("PID " + pid);
    Files.write(Common.SERVER_PID, pid.getBytes(), CREATE, TRUNCATE_EXISTING);

    ISOServer server = new ISOServer(10000, clientSide, new ThreadPool(1, 2, "simple-server"));
    server.setConfiguration(new SimpleConfiguration());
    server.addISORequestListener(pongListener());
    server.setLogger(logger, "server");
    server.run();
  }
Example #3
0
 @Override
 public void stopService() {
   if (server != null) {
     server.shutdown();
     sp.removeListener(inQueue, this);
   }
 }
Example #4
0
 private void addListeners() throws ConfigurationException {
   QFactory factory = getFactory();
   Iterator iter = getPersist().getChildren("request-listener").iterator();
   while (iter.hasNext()) {
     Element l = (Element) iter.next();
     ISORequestListener listener =
         (ISORequestListener) factory.newInstance(l.getAttributeValue("class"));
     factory.setLogger(listener, l);
     factory.setConfiguration(listener, l);
     server.addISORequestListener(listener);
   }
 }
Example #5
0
 /*
  * This method will be invoked through the SpaceListener interface we registered once
  * we noticed we had an 'in' queue.
  */
 @Override
 public void notify(Object key, Object value) {
   Object obj = sp.inp(key);
   if (obj instanceof ISOMsg) {
     ISOMsg m = (ISOMsg) obj;
     if ("LAST".equals(sendMethod)) {
       try {
         ISOChannel c = server.getLastConnectedISOChannel();
         if (c == null) {
           throw new ISOException("Server has no active connections");
         }
         if (!c.isConnected()) {
           throw new ISOException("Client disconnected");
         }
         c.send(m);
       } catch (Exception e) {
         getLog().warn("notify", e);
       }
     } else if ("ALL".equals(sendMethod)) {
       String channelNames = getISOChannelNames();
       if (channelNames != null) {
         StringTokenizer tok = new StringTokenizer(channelNames, " ");
         while (tok.hasMoreTokens()) {
           try {
             ISOChannel c = server.getISOChannel(tok.nextToken());
             if (c == null) {
               throw new ISOException("Server has no active connections");
             }
             if (!c.isConnected()) {
               throw new ISOException("Client disconnected");
             }
             c.send(m);
           } catch (Exception e) {
             getLog().warn("notify", e);
           }
         }
       }
     }
   }
 }
Example #6
0
  private void addServerSocketFactory() throws ConfigurationException {
    QFactory factory = getFactory();
    Element persist = getPersist();

    Element serverSocketFactoryElement = persist.getChild("server-socket-factory");

    if (serverSocketFactoryElement != null) {
      ISOServerSocketFactory serverSocketFactory =
          (ISOServerSocketFactory)
              factory.newInstance(serverSocketFactoryElement.getAttributeValue("class"));
      factory.setLogger(serverSocketFactory, serverSocketFactoryElement);
      factory.setConfiguration(serverSocketFactory, serverSocketFactoryElement);
      server.setSocketFactory(serverSocketFactory);
    }
  }
Example #7
0
 private void initOut() {
   Element persist = getPersist();
   outQueue = persist.getChildText("out");
   if (outQueue != null) {
     /*
      * We have an 'out' queue to send any messages to that are received
      * by the our requestListener(this).
      *
      * Note, if additional ISORequestListeners are registered with the server after
      *  this point, then they won't see anything as our process(ISOSource, ISOMsg)
      *  always return true.
      */
     server.addISORequestListener(this);
   }
 }
Example #8
0
 @Override
 public String getCountersAsString(String isoChannelName) {
   return server.getCountersAsString(isoChannelName);
 }
Example #9
0
 @Override
 public String getCountersAsString() {
   return server.getCountersAsString();
 }
Example #10
0
 @Override
 public String getISOChannelNames() {
   return server.getISOChannelNames();
 }