Пример #1
0
  public void execute(Session bot, String channel, User user, String message) {
    SimpleStringTokenizer messageToken = new SimpleStringTokenizer(message);

    int time = 0;
    String question = null;
    int countTokens = messageToken.countTokens();
    boolean numberCondition = false;

    if (countTokens > 1) {
      try {
        time = Integer.parseInt(messageToken.nextToken());
        if (time < 1) {
          bot.msg(channel, "Mindestens eine Sekunde");
          return;
        }
        question = messageToken.remainingString();
        numberCondition = true;
      } catch (NumberFormatException ex) {
      }
    }

    if (!numberCondition) {
      if (countTokens < 1) {
        bot.msg(channel, "Nicht genug Argumente");
        return;
      }
      question = message;
      time = 500;
    }

    Vote newVote = new Vote(user, question);
    Timer endVote = new Timer();

    VoteTask endTask = new VoteTask(bot, channel, newVote);

    bot.msg(channel, "Neue Abstimmung - " + newVote.getId() + ": '" + question + "'");
    endVote.schedule(endTask, ((long) time) * 1000);
  }
Пример #2
0
  private void addServlet(ServletSpec spec) {
    synchronized (servletSpecs) {
      servletSpecs.add(spec);
      try {
        // TODO make sure context has appropriate settings
        // servletContext.getSessionHandler().getSessionManager().getSessionCookieConfig().setName(name)

        addServletToContext(servletContext, spec);
      } catch (Exception ex) {
        logger.log(Level.INFO, "Could not add servlet", ex);
        lifeCycleControlConduit.vote(meemContext.getWedgeIdentifier(), false);
        return;
      }
    }
  }
Пример #3
0
  protected void startServer() {

    if (server == null) {
      // stop excessive logging
      Log.setLog(null);
      System.setProperty("DEBUG", "false");
      System.setProperty("VERBOSE", "false");

      server = new Server();
    }

    Connector connector = null;
    if (useSSL) {
      SslContextFactory contextFactory = new SslContextFactory();
      contextFactory.setKeyStore(sslKeystore);
      contextFactory.setKeyStorePassword(sslPassword);
      contextFactory.setKeyManagerPassword(sslKeyPassword);
      contextFactory.setNeedClientAuth(needClientAuth);
      connector = new SslSelectChannelConnector(contextFactory);

      // Setup JSSE keystore and set parameters here correctly
      //			connector = new SslSocketConnector();
      //			((SslSocketConnector)connector).setKeystore(sslKeystore);
      //			((SslSocketConnector)connector).setPassword(sslPassword);
      //			((SslSocketConnector)connector).setKeyPassword(sslKeyPassword);
      //			((SslSocketConnector)connector).setNeedClientAuth(needClientAuth);
      // uses an entry in the keystore called "jetty"
    } else {
      // connector = new SocketConnector();
      connector = new SelectChannelConnector();
    }
    connector.setPort(port);
    server.addConnector(connector);

    // set the Server's HandlerCollection. Other handlers will be added to the HandlerCollection
    handlerCollection = new ContextHandlerCollection();
    server.setHandler(handlerCollection);

    // create servlet context
    servletContext =
        new ServletContextHandler(
            handlerCollection, servletContextString, ServletContextHandler.SESSIONS);
    //		servletContext = new ServletContextHandler(handlerCollection, servletContextString,
    // ServletContextHandler.SESSIONS);

    // create web app context
    // webAppContext = new Context(handlerCollection, webAppContextString, Context.SESSIONS);

    try {

      // add ResourceHandlers
      addResourceHandlers();

      // add servlets to the servlet context
      // servletContext.addHandler(new SecurityHandler());
      addServletsToContext(servletContext);

      //
      addWebApps();

      // add default handler to the server
      handlerCollection.addHandler(new DefaultHandler());

      // start a Jetty
      server.start();
    } catch (BindException ex) {
      logger.log(
          Level.INFO, "Could not start web server on port " + port + ": " + ex.getMessage(), ex);
      lifeCycleControlConduit.vote(meemContext.getWedgeIdentifier(), false);
      return;
    } catch (InstantiationException ex) {
      logger.log(Level.INFO, "Could not add servlet: ", ex);
      lifeCycleControlConduit.vote(meemContext.getWedgeIdentifier(), false);
      return;
    } catch (IllegalAccessException ex) {
      logger.log(Level.INFO, "Could not add servlet: ", ex);
      lifeCycleControlConduit.vote(meemContext.getWedgeIdentifier(), false);
      return;
    } catch (ClassNotFoundException ex) {
      logger.log(Level.INFO, "Could not add servlet: ", ex);
      lifeCycleControlConduit.vote(meemContext.getWedgeIdentifier(), false);
      return;
    } catch (MultiException ex) {
      logger.log(Level.INFO, "Problem while starting the web server: ", ex);
      lifeCycleControlConduit.vote(meemContext.getWedgeIdentifier(), false);
      return;
    } catch (Exception ex) {
      logger.log(Level.INFO, "Problem while starting the web server: ", ex);
      lifeCycleControlConduit.vote(meemContext.getWedgeIdentifier(), false);
      return;
    }

    lifeCycleControlConduit.vote(meemContext.getWedgeIdentifier(), true);
  }