コード例 #1
0
ファイル: MobileV3Test.java プロジェクト: hisilicon/IoTCloud
  @Test
  public void testRecipientEnabledFor2Resources2Presences()
      throws TigaseStringprepException, NotAuthorizedException {
    String recipient = "recipient-1@localhost";
    JID recp1 = JID.jidInstanceNS(recipient + "/res1");
    JID recp2 = JID.jidInstanceNS(recipient + "/res2");
    JID connId1 = JID.jidInstanceNS("c2s@localhost/recipient1-res1");
    JID connId2 = JID.jidInstanceNS("c2s@localhost/recipient1-res2");
    XMPPResourceConnection session1 = getSession(connId1, recp1);
    getSession(connId2, recp2);

    enableMobileV3(session1, recp1);

    Packet presence =
        Packet.packetInstance(
            "presence", "sender-1@localhost/res1", recp1.toString(), StanzaType.available);
    presence.setPacketTo(connId1);
    ArrayDeque<Packet> results = new ArrayDeque<Packet>();
    results.offer(presence);
    Packet[] expected = new Packet[0]; // results.toArray(new Packet[0]);
    mobileV3.filter(presence, session1, null, results);
    Packet[] processed = results.toArray(new Packet[0]);
    Assert.assertArrayEquals(expected, processed);

    presence =
        Packet.packetInstance(
            "presence", "sender-1@localhost/res1", recp1.toString(), StanzaType.available);
    presence.setPacketTo(connId1);
    results = new ArrayDeque<Packet>();
    results.offer(presence);
    expected = new Packet[0]; // results.toArray(new Packet[0]);
    mobileV3.filter(presence, session1, null, results);
    processed = results.toArray(new Packet[0]);
    Assert.assertArrayEquals(expected, processed);

    results.clear();
    Packet p =
        Packet.packetInstance(
            "message", "sender-1@localhost/res1", recp1.toString(), StanzaType.chat);
    p.setPacketTo(connId1);
    results.offer(p);
    Packet p1 =
        Packet.packetInstance(
            "presence", "sender-1@localhost/res1", recp1.toString(), StanzaType.error);
    p1.setPacketTo(connId1);
    results.offer(p1);
    expected = new Packet[] {presence, p, p1};
    mobileV3.filter(p, session1, null, results);
    processed = results.toArray(new Packet[0]);
    Assert.assertArrayEquals(expected, processed);
  }
コード例 #2
0
 public void enqueue(DeferredSerialization ds) {
   if (m_isShutdown) {
     ds.cancel();
     return;
   }
   m_queuedWrites.offer(ds);
 }
コード例 #3
0
 /*
  * (non-Javadoc)
  *
  * @see
  * org.apache.log4j.AppenderSkeleton#append(org.apache.log4j.spi.LoggingEvent
  * )
  */
 @Override
 protected void append(LoggingEvent loggingEvent) {
   synchronized (bufferLock) {
     if (buffer.size() == capacity) {
       buffer.poll();
     }
     buffer.offer(loggingEvent);
   }
 }
コード例 #4
0
 public List<List<Integer>> zigzagLevelOrder(TreeNode root) {
   List<List<Integer>> r = new ArrayList<List<Integer>>();
   ArrayDeque<TreeNode> q = new ArrayDeque<TreeNode>();
   if (root == null) return r;
   q.offer(root);
   boolean reversedOrder = false;
   while (!q.isEmpty()) {
     int len = q.size();
     List<Integer> level = new LinkedList<Integer>();
     for (int i = 0; i < len; i++) {
       TreeNode n = q.poll();
       if (reversedOrder) level.add(0, n.val);
       else level.add(n.val);
       if (n.left != null) q.offer(n.left);
       if (n.right != null) q.offer(n.right);
     }
     r.add(level);
     reversedOrder = !reversedOrder;
   }
   return r;
 }
コード例 #5
0
ファイル: AsyncTask.java プロジェクト: jun0813/SqueezerWear
 public synchronized void execute(final Runnable r) {
   mTasks.offer(
       new Runnable() {
         public void run() {
           try {
             r.run();
           } finally {
             scheduleNext();
           }
         }
       });
   if (mActive == null) {
     scheduleNext();
   }
 }
コード例 #6
0
  public void enqueue(final ByteBuffer buf) {
    assert (!buf.isDirect()); // Don't queue direct buffers, they leak memory without a container
    if (buf.remaining() == 0) {
      throw new IllegalArgumentException("Attempted to queue a zero length buffer");
    }
    if (m_isShutdown) return;
    m_queuedWrites.offer(
        new DeferredSerialization() {

          @Override
          public void serialize(final ByteBuffer outbuf) throws IOException {
            outbuf.put(buf);
          }

          @Override
          public void cancel() {}

          @Override
          public int getSerializedSize() {
            return buf.remaining();
          }
        });
  }
コード例 #7
0
ファイル: TCPWrap.java プロジェクト: huntc/trireme
 private void queueWrite(QueuedWrite qw) {
   addInterest(SelectionKey.OP_WRITE);
   writeQueue.offer(qw);
 }
コード例 #8
0
 // Locked by this.
 private void releaseAggregatedStatsLocked(AggregatedStats[] array) {
   for (int i = 0; i < array.length; i++) {
     array[i] = null;
   }
   mStatsArrays.offer(array);
 }
コード例 #9
0
ファイル: MobileV3Test.java プロジェクト: hisilicon/IoTCloud
  @Test
  public void testRecipientEnabledFor2ResourcesMixed()
      throws TigaseStringprepException, NotAuthorizedException {
    String recipient = "recipient-1@localhost";
    JID recp1 = JID.jidInstanceNS(recipient + "/res1");
    JID recp2 = JID.jidInstanceNS(recipient + "/res2");
    JID connId1 = JID.jidInstanceNS("c2s@localhost/recipient1-res1");
    JID connId2 = JID.jidInstanceNS("c2s@localhost/recipient1-res2");
    XMPPResourceConnection session1 = getSession(connId1, recp1);
    getSession(connId2, recp2);

    enableMobileV3(session1, recp1);

    Packet presence =
        Packet.packetInstance(
            "presence", "sender-1@localhost/res1", recp1.toString(), StanzaType.available);
    presence.setPacketTo(connId1);
    ArrayDeque<Packet> results = new ArrayDeque<Packet>();
    results.offer(presence);
    Packet[] expected = new Packet[0]; // results.toArray(new Packet[0]);
    mobileV3.filter(presence, session1, null, results);
    Packet[] processed = results.toArray(new Packet[0]);
    Assert.assertArrayEquals(expected, processed);

    results.clear();
    Packet m1 =
        Packet.packetInstance("message", recp2.toString(), recp1.toString(), StanzaType.chat);
    Element receivedEl =
        new Element("received", new String[] {"xmlns"}, new String[] {"urn:xmpp:carbons:2"});
    Element forwardedEl =
        new Element("forwarded", new String[] {"xmlns"}, new String[] {"urn:xmpp:forward:0"});
    forwardedEl.addChild(
        new Element(
            "message",
            new String[] {"from", "to"},
            new String[] {recp2.toString(), "sender-1@localhost/res1"}));
    receivedEl.addChild(forwardedEl);
    m1.getElement().addChild(receivedEl);
    m1.setPacketTo(connId1);
    results.offer(m1);
    expected = new Packet[0];
    mobileV3.filter(m1, session1, null, results);
    processed = results.toArray(new Packet[0]);
    Assert.assertArrayEquals(expected, processed);

    results.clear();
    presence =
        Packet.packetInstance(
            "presence", "sender-1@localhost/res1", recp1.toString(), StanzaType.available);
    presence.setPacketTo(connId1);
    results.offer(presence);
    expected = new Packet[0]; // results.toArray(new Packet[0]);
    mobileV3.filter(presence, session1, null, results);
    processed = results.toArray(new Packet[0]);
    Assert.assertArrayEquals(expected, processed);

    results.clear();
    Packet p =
        Packet.packetInstance(
            "message", "sender-1@localhost/res1", recp1.toString(), StanzaType.chat);
    p.setPacketTo(connId1);
    results.offer(p);
    Packet p1 =
        Packet.packetInstance(
            "presence", "sender-1@localhost/res1", recp1.toString(), StanzaType.error);
    p1.setPacketTo(connId1);
    results.offer(p1);
    expected = new Packet[] {presence, m1, p, p1};
    mobileV3.filter(p, session1, null, results);
    processed = results.toArray(new Packet[0]);
    Assert.assertArrayEquals(expected, processed);
  }