Package org.coweb.bots.transport

Examples of org.coweb.bots.transport.Transport


   */
  @SuppressWarnings("unchecked")
  public Transport getServiceBroker(String serviceName) {

    log.fine("ServiceHandler::getServiceBroker for " + serviceName);
    Transport broker = this.brokers.get(serviceName);
    if (broker != null)
      return broker;

    log.fine(this.cowebConfig.get("bots").toString());
    Object[] botConfigs = (Object[]) this.cowebConfig.get("bots");
    if (botConfigs == null) {
      return null;
    }

    Map<String, Object> botConfig = null;
    for (int i = 0; i < botConfigs.length; i++) {
      Map<String, Object> tmp = (Map<String, Object>) botConfigs[i];
      String s = (String) tmp.get("service");

      if (s.equals(serviceName)) {
        botConfig = tmp;
        break;
      }
    }

    if (botConfig == null)
      return null;

    String brokerStr = (String) botConfig.get("broker");
    if (brokerStr == null) {
      if (botConfig.get("class") != null)
        brokerStr = "org.coweb.bots.transport.LocalTransport";
      else
        return null;
    }

    try {
      Class<? extends Transport> clazz = Class.forName(brokerStr)
          .asSubclass(Transport.class);
      broker = clazz.newInstance();
    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }

    broker.setBotConfig(botConfig);
    broker.setSessionId(this.sessionId);
    this.brokers.put(serviceName, broker);
    return broker;
  }
View Full Code Here


    if (serviceName == null) {
      throw new IOException("improper subscription to channel "
          + message.getChannel());
    }

    Transport broker = this.getServiceBroker(serviceName);
    if (broker == null) {
      throw new IOException("no broker to handle this service " + serviceName);
    }

    broker.subscribeUser(client, pub);
  }
View Full Code Here

  /**
   */
  public void subscribeModerator(SessionModerator mod, String serviceName)
      throws IOException {
    Transport broker = this.getServiceBroker(serviceName);
    if (broker == null) {
      throw new IOException("no broker to handle this service " + serviceName);
    }

    broker.subscribeUser(mod.getServerSession(), true);
  }
View Full Code Here

    boolean pub = true;
    if (channel.startsWith("/service"))
      pub = false;
    String serviceName = getServiceNameFromSubscription(message, pub);

    Transport broker = this.getServiceBroker(serviceName);
    if (null == broker)
      throw new IOException("no broker to handle this service " + serviceName);

    HashMap<String, Object> data = new HashMap<String, Object>();
    data.put("error", true);
    ServerChannel ch = broker.getResponseChannel();
    client.deliver(broker.getServer(), ch.getId(), data, null);
  }
View Full Code Here

    String serviceName = getServiceNameFromSubscription(message, pub);
    if (serviceName == null)
      throw new IOException("improper subscription to channel "
          + message.getChannel());

    Transport broker = this.getServiceBroker(serviceName);
    if (broker == null)
      throw new IOException("no broker to handle this service "
          + serviceName);

    broker.unsubscribeUser(client, pub);
  }
View Full Code Here

    String serviceName = getServiceNameFromMessage(message, false);
    if (serviceName == null)
      throw new IOException("improper request channel "
          + message.getChannel());

    Transport broker = this.getServiceBroker(serviceName);
    if (broker == null)
      throw new IOException("no broker to handle this service "
          + serviceName);

    Map<String, Object> data = message.getDataAsMap();
    String replyToken = (String) data.get("topic");

    Map<String, Object> resp = new HashMap<String, Object>();
    resp.put("error", true);
    resp.put("topic", replyToken);

    client.deliver(broker.getServer(), "/service/bot/" +
        broker.getServiceName() + "/response", resp, null);
    return;
  }
View Full Code Here

    String serviceName = getServiceNameFromMessage(message, false);
    if (serviceName == null)
      throw new IOException("improper request channel "
          + message.getChannel());

    Transport broker = this.getServiceBroker(serviceName);
    if (broker == null)
      throw new IOException("no broker to handle this service "
          + serviceName);

    broker.userRequest(client, message);
    return;
  }
View Full Code Here

TOP

Related Classes of org.coweb.bots.transport.Transport

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.