@Test(groups = "dev")
  public void sinkSingleModelTest() throws EventDeliveryException {
    ctx.put(MongoSink.MODEL, MongoSink.CollectionModel.single.name());

    MongoSink sink = new MongoSink();
    Configurables.configure(sink, ctx);

    sink.setChannel(channel);
    sink.start();

    Transaction tx = channel.getTransaction();
    tx.begin();
    JSONObject msg = new JSONObject();
    msg.put("name", "test");
    msg.put("age", 11);
    msg.put("birthday", new Date().getTime());

    Event e = EventBuilder.withBody(msg.toJSONString().getBytes());
    channel.put(e);
    tx.commit();
    tx.close();

    sink.process();
    sink.stop();

    DB db = mongo.getDB("test_events");
    DBCollection collection = db.getCollection("test_log");
    DBCursor cursor = collection.find(new BasicDBObject(msg));
    assertTrue(cursor.hasNext());
    DBObject dbObject = cursor.next();
    assertNotNull(dbObject);
    assertEquals(dbObject.get("name"), msg.get("name"));
    assertEquals(dbObject.get("age"), msg.get("age"));
    assertEquals(dbObject.get("birthday"), msg.get("birthday"));
  }
  private void ban(MessageContext context, String args) {
    if (args.isEmpty()) {
      return;
    }
    String[] split = args.split(" ");
    List<String> banned = new ArrayList<>();
    List<String> failed = new ArrayList<>();
    Channel channel = context.getChannel();
    for (String userStr : split) {
      User user = findUser(context, userStr);
      String userId = user.getId();
      if (user == NO_USER) {
        userId = userStr;
      }

      if (banChecked(channel, context.getAuthor(), user, context.getServer())) {
        banned.add(userId + " " + user.getUsername());
      } else {
        failed.add(userId + " " + user.getUsername());
      }
    }

    if (channel.getId() != null) {
      StringJoiner joiner = new StringJoiner("\n");
      for (String s : banned) {
        String[] pair = s.split(" ", 2);
        joiner.add(loc.localize("commands.mod.ban.response", pair[1], pair[0]));
      }
      apiClient.sendMessage(joiner.toString(), channel);
    }
  }
  /**
   * Sets the values of the properties of a specific <tt>ColibriConferenceIQ</tt> to the values of
   * the respective properties of this instance. Thus, the specified <tt>iq</tt> may be thought of
   * as a description of this instance.
   *
   * <p><b>Note</b>: The copying of the values is deep i.e. the <tt>Contents</tt>s of this instance
   * are described in the specified <tt>iq</tt>.
   *
   * @param iq the <tt>ColibriConferenceIQ</tt> to set the values of the properties of this instance
   *     on
   */
  public void describeDeep(ColibriConferenceIQ iq) {
    describeShallow(iq);

    if (isRecording()) {
      ColibriConferenceIQ.Recording recordingIQ =
          new ColibriConferenceIQ.Recording(State.ON.toString());
      recordingIQ.setDirectory(getRecordingDirectory());
      iq.setRecording(recordingIQ);
    }
    for (Content content : getContents()) {
      ColibriConferenceIQ.Content contentIQ = iq.getOrCreateContent(content.getName());

      for (Channel channel : content.getChannels()) {
        if (channel instanceof SctpConnection) {
          ColibriConferenceIQ.SctpConnection sctpConnectionIQ =
              new ColibriConferenceIQ.SctpConnection();

          channel.describe(sctpConnectionIQ);
          contentIQ.addSctpConnection(sctpConnectionIQ);
        } else {
          ColibriConferenceIQ.Channel channelIQ = new ColibriConferenceIQ.Channel();

          channel.describe(channelIQ);
          contentIQ.addChannel(channelIQ);
        }
      }
    }
  }
Exemple #4
0
 private static void setOOBPoolSize(JChannel... channels) {
   for (Channel channel : channels) {
     TP transport = channel.getProtocolStack().getTransport();
     transport.setOOBThreadPoolMinThreads(1);
     transport.setOOBThreadPoolMaxThreads(2);
   }
 }
  @Test(groups = "dev")
  public void autoWrapTest() throws EventDeliveryException {
    ctx.put(MongoSink.AUTO_WRAP, Boolean.toString(true));
    ctx.put(MongoSink.DB_NAME, "test_wrap");

    MongoSink sink = new MongoSink();
    Configurables.configure(sink, ctx);

    sink.setChannel(channel);
    sink.start();

    Transaction tx = channel.getTransaction();
    tx.begin();
    String msg =
        "2012/10/26 11:23:08 [error] 7289#0: *6430831 open() \"/usr/local/nginx/html/50x.html\" failed (2: No such file or directory), client: 10.160.105.161, server: sg15.redatoms.com, request: \"POST /mojo/ajax/embed HTTP/1.0\", upstream: \"fastcgi://unix:/tmp/php-fpm.sock:\", host: \"sg15.redatoms.com\", referrer: \"http://sg15.redatoms.com/mojo/mobile/package\"";

    Event e = EventBuilder.withBody(msg.getBytes());
    channel.put(e);
    tx.commit();
    tx.close();

    sink.process();
    sink.stop();

    DB db = mongo.getDB("test_wrap");
    DBCollection collection = db.getCollection("test_log");
    DBCursor cursor = collection.find(new BasicDBObject(MongoSink.DEFAULT_WRAP_FIELD, msg));
    assertTrue(cursor.hasNext());
    DBObject dbObject = cursor.next();
    assertNotNull(dbObject);
    assertEquals(dbObject.get(MongoSink.DEFAULT_WRAP_FIELD), msg);
    mongo.dropDatabase("test_wrap");
  }
Exemple #6
0
 private static void setStableGossip(JChannel... channels) {
   for (Channel channel : channels) {
     ProtocolStack stack = channel.getProtocolStack();
     STABLE stable = (STABLE) stack.findProtocol(STABLE.class);
     stable.setDesiredAverageGossip(2000);
   }
 }
Exemple #7
0
 public void newchild(Widget w) {
   if (w instanceof Channel) {
     Channel chan = (Channel) w;
     select(chan);
     chansel.add(chan);
     if (!expanded) chan.hide();
   }
 }
 /** Close the connection. */
 public synchronized void close() {
   if (!closed && channel != null) {
     ConnectionWatchdog watchdog = channel.getPipeline().get(ConnectionWatchdog.class);
     watchdog.setReconnect(false);
     closed = true;
     channel.close();
   }
 }
Exemple #9
0
 public void select(Channel chan) {
   Channel prev = sel;
   sel = chan;
   if (expanded) {
     if (prev != null) prev.hide();
     sel.show();
     resize(sz);
   }
 }
Exemple #10
0
 /** Close all channels. */
 public void closeAll() {
   for (Channel channel : channels) {
     try {
       channel.close();
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 }
Exemple #11
0
  public void testMergeWithAsymetricViewsCoordIsolated() {
    // Isolate the coord
    Address coord = a.getView().getCreator();
    System.out.println("Isolating coord: " + coord);
    List<Address> members = new ArrayList<>();
    members.add(coord);
    View coord_view = new View(coord, 4, members);
    System.out.println("coord_view: " + coord_view);
    Channel coord_channel = findChannel(coord);
    System.out.println("coord_channel: " + coord_channel.getAddress());

    MutableDigest digest = new MutableDigest(coord_view.getMembersRaw());
    NAKACK2 nakack = (NAKACK2) coord_channel.getProtocolStack().findProtocol(NAKACK2.class);
    digest.merge(nakack.getDigest(coord));

    GMS gms = (GMS) coord_channel.getProtocolStack().findProtocol(GMS.class);
    gms.installView(coord_view, digest);
    System.out.println("gms.getView() " + gms.getView());

    System.out.println("Views are:");
    for (JChannel ch : Arrays.asList(a, b, c, d))
      System.out.println(ch.getAddress() + ": " + ch.getView());

    JChannel merge_leader = findChannel(coord);
    MyReceiver receiver = new MyReceiver();
    merge_leader.setReceiver(receiver);

    System.out.println("merge_leader: " + merge_leader.getAddressAsString());

    System.out.println("Injecting MERGE event into merge leader " + merge_leader.getAddress());
    Map<Address, View> merge_views = new HashMap<>(4);
    merge_views.put(a.getAddress(), a.getView());
    merge_views.put(b.getAddress(), b.getView());
    merge_views.put(c.getAddress(), c.getView());
    merge_views.put(d.getAddress(), d.getView());

    gms = (GMS) merge_leader.getProtocolStack().findProtocol(GMS.class);
    gms.up(new Event(Event.MERGE, merge_views));

    Util.waitUntilAllChannelsHaveSameSize(10000, 1000, a, b, c, d);

    System.out.println("Views are:");
    for (JChannel ch : Arrays.asList(a, b, c, d)) {
      View view = ch.getView();
      System.out.println(ch.getAddress() + ": " + view);
      assert view.size() == 4;
    }
    MergeView merge_view = receiver.getView();
    System.out.println("merge_view = " + merge_view);
    assert merge_view.size() == 4;
    assert merge_view.getSubgroups().size() == 2;

    for (View view : merge_view.getSubgroups())
      assert contains(view, a.getAddress())
          || contains(view, b.getAddress(), c.getAddress(), d.getAddress());
  }
Exemple #12
0
 /**
  * Create a channel initialized with the specified configuration.
  *
  * @param config the channel configuration
  * @param start initial state
  */
 public Channel createChannel(ChannelConfig config, boolean start) {
   Channel channel = new Channel(config);
   channel.setName("channel: " + config.getName());
   if (start) {
     channel.start();
   }
   channels.add(channel);
   channelMap.put(config.getName().toLowerCase(), channel);
   return channel;
 }
Exemple #13
0
  /** Remove a channel. */
  public void removeChannel(String name) {
    // get the channel
    Channel channel = getChannel(name);

    removeChannel(channel);

    // close it as soon as the last client leaves
    channel.getConfig().setPersistent(false);
    channel.send(new ShutdownMessage());
  }
Exemple #14
0
  /**
   * Tells if a non private channel is available for a client using the specified protocol.
   *
   * @param protocol the name of the protocol used
   * @since 0.3
   */
  public boolean hasCompatibleChannels(String protocol) {
    for (Channel chan : channels) {
      if (!chan.getConfig().isPasswordProtected()
          && chan.getConfig().isProtocolAccepted(protocol)) {
        return true;
      }
    }

    return false;
  }
  @Test(groups = "dev")
  public void timestampExistingFieldTest() throws EventDeliveryException, ParseException {
    ctx.put(MongoSink.MODEL, MongoSink.CollectionModel.dynamic.name());
    String tsField = "createdOn";
    ctx.put(MongoSink.TIMESTAMP_FIELD, tsField);
    MongoSink sink = new MongoSink();
    Configurables.configure(sink, ctx);

    sink.setChannel(channel);
    sink.start();

    JSONObject msg = new JSONObject();
    msg.put("age", 11);
    msg.put("birthday", new Date().getTime());
    String dateText = "2013-02-19T14:20:53+08:00";
    msg.put(tsField, dateText);

    Transaction tx;

    for (int i = 0; i < 10; i++) {
      tx = channel.getTransaction();
      tx.begin();
      msg.put("name", "test" + i);
      JSONObject header = new JSONObject();
      header.put(MongoSink.COLLECTION, "my_events");
      header.put(MongoSink.DB_NAME, "dynamic_db");

      Event e = EventBuilder.withBody(msg.toJSONString().getBytes(), header);
      channel.put(e);
      tx.commit();
      tx.close();
    }
    sink.process();
    sink.stop();

    msg.put(tsField, MongoSink.dateTimeFormatter.parseDateTime(dateText).toDate());
    for (int i = 0; i < 10; i++) {
      msg.put("name", "test" + i);

      System.out.println("i = " + i);

      DB db = mongo.getDB("dynamic_db");
      DBCollection collection = db.getCollection("my_events");
      DBCursor cursor = collection.find(new BasicDBObject(msg));
      assertTrue(cursor.hasNext());
      DBObject dbObject = cursor.next();
      assertNotNull(dbObject);
      assertEquals(dbObject.get("name"), msg.get("name"));
      assertEquals(dbObject.get("age"), msg.get("age"));
      assertEquals(dbObject.get("birthday"), msg.get("birthday"));
      assertTrue(dbObject.get(tsField) instanceof Date);
      System.out.println("ts = " + dbObject.get(tsField));
    }
  }
Exemple #16
0
  public ArrayList<Feedback> readFeedbacks(long idPost) {
    RssParser parser = null;
    Rss rss = null;
    // System.out.println("right? "+post);
    try {
      parser = RssParserFactory.createDefault();
      rss = parser.parse(new URL(boardAddress + "feedbacks?action=READ&FeedbackName=" + idPost));
    } catch (RssParserException e) {
      System.out.println(boardAddress + "feedbacks?action=READ&FeedbackName=" + idPost);
      System.out.println("RssParserException");
      return null;
    } catch (MalformedURLException e) {
      System.out.println("MalformedURLException");
      return null;
    } catch (IOException e) {
      System.out.println("IOException");
      return null;
    }

    Channel c = rss.getChannel();
    if (c.getItems() == null) {
      System.out.println("Non ci sono Feedback");
      return new ArrayList<Feedback>();
    }
    ArrayList<Item> items = new ArrayList<Item>(c.getItems());
    Iterator<Item> iter = items.iterator();
    ArrayList<Feedback> lista = new ArrayList<Feedback>();
    while (iter.hasNext()) {
      Item x = iter.next();
      String description = "";
      String feed = "";
      Title titolo = Title.AGREE;
      try {
        description = x.getDescription().getText();
      } catch (NullPointerException e) {
      }
      try {
        feed = x.getTitle().getText();
      } catch (NullPointerException e) {
      }
      if (feed != null) {
        if (!feed.isEmpty()) {
          if (feed.equals("AGREE")) titolo = Title.AGREE;
          else if (feed.equals("DISAGREE")) titolo = Title.DISAGREE;
          else if (feed.equals("PARTIALLY_AGREE")) titolo = Title.PARTIALLY_AGREE;
          else if (feed.equals("DETRACTOR")) titolo = Title.DETRACTOR;
          else continue;
        }
      } else continue;
      Date data = getPubDate(x);
      lista.add(new Feedback(description, titolo, data));
    }
    return lista;
  }
Exemple #17
0
    public void testRoutingInvalidRoutes() throws Exception {
        ConnectionFactory factory = new ConnectionFactory();
        com.rabbitmq.client.Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare("transient", false, false, false, null);
        connection.close();

        for (String dest : Arrays.asList("/exchange/missing", "/queue/transient", "/fruit/orange")) {
            routeInvalidSource(dest);
            routeInvalidTarget(dest);
        }
    }
Exemple #18
0
 /** handle the connection event */
 public void connectionMade(final Channel channel) {
   try {
     if (channel == _lowerChannel) {
       _lowerMonitor = channel.addMonitorValue(this, Monitor.VALUE);
     } else if (channel == _upperChannel) {
       _upperMonitor = channel.addMonitorValue(this, Monitor.VALUE);
     }
     Channel.flushIO();
   } catch (ConnectionException exception) {
   } catch (MonitorException excepiton) {
   }
 }
 public MessageDispatcher(Channel channel, MessageListener l, MembershipListener l2) {
   this.channel = channel;
   prot_adapter = new ProtocolAdapter();
   if (channel != null) {
     local_addr = channel.getAddress();
     channel.addChannelListener(this);
   }
   setMessageListener(l);
   setMembershipListener(l2);
   if (channel != null) installUpHandler(prot_adapter, true);
   start();
 }
Exemple #20
0
  /**
   * Looks for a channel with room left.
   *
   * @return <tt>null</tt> if there is no room left in all available channels
   * @deprecated
   */
  public Channel getOpenedChannel() {
    Channel channel = null;
    Iterator<Channel> it = channels.iterator();
    while (it.hasNext() && channel == null) {
      Channel channel2 = it.next();
      if (!channel2.isFull()) {
        channel = channel2;
      }
    }

    return channel;
  }
Exemple #21
0
  private void send(
      final Address dest, final int num_msgs, final int num_threads, final double oob_prob)
      throws Exception {
    if (num_threads <= 0) throw new IllegalArgumentException("number of threads <= 0");

    if (num_msgs % num_threads != 0)
      throw new IllegalArgumentException(
          "number of messages ( "
              + num_msgs
              + ") needs to be divisible by "
              + "the number o threads ("
              + num_threads
              + ")");

    if (num_threads > 1) {
      final int msgs_per_thread = num_msgs / num_threads;
      Thread[] threads = new Thread[num_threads];
      final AtomicInteger counter = new AtomicInteger(0);
      for (int i = 0; i < threads.length; i++) {
        threads[i] =
            new Thread() {
              public void run() {
                for (int j = 0; j < msgs_per_thread; j++) {
                  Channel sender = Util.tossWeightedCoin(0.5) ? a : b;
                  boolean oob = Util.tossWeightedCoin(oob_prob);
                  int num = counter.incrementAndGet();
                  Message msg = new Message(dest, null, num);
                  if (oob) msg.setFlag(Message.OOB);
                  try {
                    sender.send(msg);
                  } catch (Exception e) {
                    e.printStackTrace();
                  }
                }
              }
            };
        threads[i].start();
      }
      for (int i = 0; i < threads.length; i++) {
        threads[i].join(20000);
      }
      return;
    }

    for (int i = 0; i < num_msgs; i++) {
      Channel sender = Util.tossWeightedCoin(0.5) ? a : b;
      boolean oob = Util.tossWeightedCoin(oob_prob);
      Message msg = new Message(dest, null, i);
      if (oob) msg.setFlag(Message.OOB);
      sender.send(msg);
    }
  }
Exemple #22
0
    /** set a new channel whose limits we wish to monitor */
    public void setChannel(final Channel channel) {
      synchronized (this) {
        if (_lowerChannel != null) {
          _lowerChannel.removeConnectionListener(this);
          if (_lowerMonitor != null) {
            _lowerMonitor.clear();
            _lowerMonitor = null;
          }
        }

        final String lowerLimitPV = channel.channelName() + ".LOPR";
        _lowerChannel = ChannelFactory.defaultFactory().getChannel(lowerLimitPV);
        _lowerChannel.addConnectionListener(this);
        _lowerChannel.requestConnection();

        if (_upperChannel != null) {
          _upperChannel.removeConnectionListener(this);
          if (_upperMonitor != null) {
            _upperMonitor.clear();
            _upperMonitor = null;
          }
        }

        final String upperLimitPV = channel.channelName() + ".HOPR";
        _upperChannel = ChannelFactory.defaultFactory().getChannel(upperLimitPV);
        _upperChannel.addConnectionListener(this);
        _upperChannel.requestConnection();
      }
    }
  @Override
  public synchronized void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e)
      throws Exception {
    channel = ctx.getChannel();

    List<Command<K, V, ?>> tmp = new ArrayList<Command<K, V, ?>>(queue.size() + 2);

    if (password != null) {
      CommandArgs<K, V> args = new CommandArgs<K, V>(codec).add(password);
      tmp.add(new Command<K, V, String>(AUTH, new StatusOutput<K, V>(codec), args, false));
    }

    if (db != 0) {
      CommandArgs<K, V> args = new CommandArgs<K, V>(codec).add(db);
      tmp.add(new Command<K, V, String>(SELECT, new StatusOutput<K, V>(codec), args, false));
    }

    tmp.addAll(queue);
    queue.clear();

    for (Command<K, V, ?> cmd : tmp) {
      if (!cmd.isCancelled()) {
        queue.add(cmd);
        channel.write(cmd);
      }
    }

    tmp.clear();
  }
Exemple #24
0
 public void resize(Coord sz) {
   super.resize(sz);
   if (in != null) {
     in.c = new Coord(0, this.sz.y - 20);
     in.resize(new Coord(this.sz.x, 20));
   }
 }
Exemple #25
0
 private void expand() {
   resize(new Coord(sz.x, 100));
   setcanfocus(true);
   if (sel != null) sel.show();
   chansel.show();
   expanded = true;
 }
    /**
     * Appends the XML <tt>String</tt> representation of this <tt>Content</tt> to a specific
     * <tt>StringBuilder</tt>.
     *
     * @param xml the <tt>StringBuilder</tt> to which the XML <tt>String</tt> representation of this
     *     <tt>Content</tt> is to be appended
     */
    public void toXML(StringBuilder xml) {
      xml.append('<').append(ELEMENT_NAME);
      xml.append(' ').append(NAME_ATTR_NAME).append("='").append(getName()).append('\'');

      List<Channel> channels = getChannels();
      List<SctpConnection> connections = getSctpConnections();

      if (channels.size() == 0 && connections.size() == 0) {
        xml.append(" />");
      } else {
        xml.append('>');
        for (Channel channel : channels) channel.toXML(xml);
        for (SctpConnection conn : connections) conn.toXML(xml);
        xml.append("</").append(ELEMENT_NAME).append('>');
      }
    }
Exemple #27
0
 private void contract() {
   resize(new Coord(sz.x, 50));
   setcanfocus(false);
   if (sel != null) sel.hide();
   chansel.hide();
   expanded = false;
 }
Exemple #28
0
  /** Remove a channel. */
  public void removeChannel(Channel channel) {
    String name = channel.getConfig().getName().toLowerCase();

    // unregister the channel
    channels.remove(channel);
    channelMap.remove(name.toLowerCase());
  }
  /**
   * Checks whether RTP packets from {@code sourceChannel} should be forwarded to {@link #channel}.
   *
   * @param sourceChannel the channel.
   * @return {@code true} iff RTP packets from {@code sourceChannel} should be forwarded to {@link
   *     #channel}.
   */
  public boolean isForwarded(Channel sourceChannel) {
    if (lastN < 0 && currentLastN < 0) {
      // If Last-N is disabled, we forward everything.
      return true;
    }

    if (sourceChannel == null) {
      logger.warn("Invalid sourceChannel: null.");
      return false;
    }

    Endpoint channelEndpoint = sourceChannel.getEndpoint();
    if (channelEndpoint == null) {
      logger.warn("sourceChannel has no endpoint.");
      return false;
    }

    if (forwardedEndpoints == INITIAL_EMPTY_LIST) {
      // LastN is enabled, but we haven't yet initialized the list of
      // endpoints in the conference.
      initializeConferenceEndpoints();
    }

    // This may look like a place to optimize, because we query an unordered
    // list (in O(n)) and it executes on each video packet if lastN is
    // enabled. However, the size of  forwardedEndpoints is restricted to
    // lastN and so small enough that it is not worth optimizing.
    return forwardedEndpoints.contains(channelEndpoint.getID());
  }
  @Test(groups = "dev")
  public void sinkDynamicDbTest() throws EventDeliveryException {
    ctx.put(MongoSink.MODEL, MongoSink.CollectionModel.dynamic.name());
    MongoSink sink = new MongoSink();
    Configurables.configure(sink, ctx);

    sink.setChannel(channel);
    sink.start();

    JSONObject msg = new JSONObject();
    msg.put("age", 11);
    msg.put("birthday", new Date().getTime());

    Transaction tx;

    for (int i = 0; i < 10; i++) {
      tx = channel.getTransaction();
      tx.begin();
      msg.put("name", "test" + i);
      JSONObject header = new JSONObject();
      header.put(MongoSink.COLLECTION, "my_events");
      header.put(MongoSink.DB_NAME, "dynamic_db");

      Event e = EventBuilder.withBody(msg.toJSONString().getBytes(), header);
      channel.put(e);
      tx.commit();
      tx.close();
    }
    sink.process();
    sink.stop();

    for (int i = 0; i < 10; i++) {
      msg.put("name", "test" + i);

      System.out.println("i = " + i);

      DB db = mongo.getDB("dynamic_db");
      DBCollection collection = db.getCollection("my_events");
      DBCursor cursor = collection.find(new BasicDBObject(msg));
      assertTrue(cursor.hasNext());
      DBObject dbObject = cursor.next();
      assertNotNull(dbObject);
      assertEquals(dbObject.get("name"), msg.get("name"));
      assertEquals(dbObject.get("age"), msg.get("age"));
      assertEquals(dbObject.get("birthday"), msg.get("birthday"));
    }
  }