@Override
 public void receive(Message msg) {
   try {
     LOG.debug(
         "Table "
             + Bytes.toString(idxCoprocessor.getTableName())
             + " received message: Table "
             + Bytes.toString((byte[]) msg.getObject())
             + " must update its index columns cache.");
     if (Arrays.equals((byte[]) msg.getObject(), idxCoprocessor.getTableName())) {
       LOG.debug(
           "Table "
               + Bytes.toString(idxCoprocessor.getTableName())
               + " is updating its indexed columns cache.");
       idxCoprocessor.initIndexedColumnsForTable();
     }
   } catch (IOException e1) {
     LOG.error("Failed to update from the master index table.", e1);
   } catch (Exception e) {
     LOG.error(
         "Failed to read contents of message; updating from master index table just in case.", e);
     try {
       idxCoprocessor.initIndexedColumnsForTable();
     } catch (IOException e1) {
       LOG.error("Failed to update from the master index table.", e1);
     }
   }
 }
Пример #2
0
  /*
   * (non-Javadoc)
   *
   * @see org.jgroups.ReceiverAdapter#receive(org.jgroups.Message)
   */
  @Override
  public void receive(Message msg) {
    // TODO Auto-generated method stub
    System.out.println(msg.getSrc() + ":" + msg.getObject());

    synchronized (state) {
      state.add(msg.getSrc() + ":" + msg.getObject());
    }
  }
 public static String print(List<Message> list) {
   StringBuilder sb = new StringBuilder();
   for (Message msg : list) {
     sb.append(msg.getSrc()).append(": ").append(msg.getObject()).append(" ");
   }
   return sb.toString();
 }
Пример #4
0
 public Object down(Event evt) {
   if (evt.getType() == Event.MSG) {
     Message msg = (Message) evt.getArg();
     if (msg.getLength() > 0) {
       try {
         Long payload = msg.getObject();
         if (payload != null) {
           if (payload == seqno) {
             synchronized (this) {
               if (num_discards < 3) {
                 num_discards++;
                 return null;
               }
             }
           }
           if (payload == duplicate) { // inject a duplicate message
             super.down(
                 evt); // pass it down, will passed down a second time by the default
                       // down_prot.down(evt)
           }
         }
       } catch (Throwable t) {;
       }
     }
   }
   return down_prot.down(evt);
 }
Пример #5
0
  /**
   * Message contains MethodCall. Execute it against *this* object and return result. Use
   * MethodCall.invoke() to do this. Return result.
   */
  public Object handle(Message req) throws Exception {
    if (server_obj == null) {
      log.error(Util.getMessage("NoMethodHandlerIsRegisteredDiscardingRequest"));
      return null;
    }

    if (req == null || req.getLength() == 0) {
      log.error(Util.getMessage("MessageOrMessageBufferIsNull"));
      return null;
    }

    Object body =
        req_marshaller != null
            ? req_marshaller.objectFromBuffer(req.getRawBuffer(), req.getOffset(), req.getLength())
            : req.getObject();

    if (!(body instanceof MethodCall))
      throw new IllegalArgumentException("message does not contain a MethodCall object");

    MethodCall method_call = (MethodCall) body;

    if (log.isTraceEnabled()) log.trace("[sender=%s], method_call: %s", req.getSrc(), method_call);

    if (method_call.getMode() == MethodCall.ID) {
      if (method_lookup == null)
        throw new Exception(
            String.format(
                "MethodCall uses ID=%d, but method_lookup has not been set", method_call.getId()));
      Method m = method_lookup.findMethod(method_call.getId());
      if (m == null) throw new Exception("no method found for " + method_call.getId());
      method_call.setMethod(m);
    }

    return method_call.invoke(server_obj);
  }
Пример #6
0
  public Object up(Event evt) {
    switch (evt.getType()) {
      case Event.MSG:
        Message msg = (Message) evt.getArg();
        LockingHeader hdr = (LockingHeader) msg.getHeader(id);
        if (hdr == null) break;

        Request req = (Request) msg.getObject();
        if (log.isTraceEnabled())
          log.trace("[" + local_addr + "] <-- [" + msg.getSrc() + "] " + req);
        switch (req.type) {
          case GRANT_LOCK:
          case RELEASE_LOCK:
            handleLockRequest(req);
            break;
          case LOCK_GRANTED:
            handleLockGrantedResponse(req.lock_name, req.owner, msg.getSrc());
            break;
          case LOCK_DENIED:
            handleLockDeniedResponse(req.lock_name, req.owner);
            break;
          case CREATE_LOCK:
            handleCreateLockRequest(req.lock_name, req.owner);
            break;
          case DELETE_LOCK:
            handleDeleteLockRequest(req.lock_name);
            break;
          case COND_SIG:
          case COND_SIG_ALL:
            handleSignalRequest(req);
            break;
          case LOCK_AWAIT:
            handleAwaitRequest(req.lock_name, req.owner);
            handleLockRequest(req);
            break;
          case DELETE_LOCK_AWAIT:
            handleDeleteAwaitRequest(req.lock_name, req.owner);
            break;
          case SIG_RET:
            handleSignalResponse(req.lock_name, req.owner);
            break;
          case CREATE_AWAITER:
            handleCreateAwaitingRequest(req.lock_name, req.owner);
            break;
          case DELETE_AWAITER:
            handleDeleteAwaitingRequest(req.lock_name, req.owner);
            break;
          default:
            log.error("Request of type " + req.type + " not known");
            break;
        }
        return null;

      case Event.VIEW_CHANGE:
        handleView((View) evt.getArg());
        break;
    }
    return up_prot.up(evt);
  }
Пример #7
0
    public void receive(Message msg) {
      if (!msg.isFlagSet(Message.OOB)) {
        lock.lock();
        lock.unlock();
      }

      msgs.add((Integer) msg.getObject());
    }
Пример #8
0
  public void receive(Message msg) {
    String recievedMsg = msg.getObject().toString();
    System.out.println(msg.getSrc() + ": " + recievedMsg);

    if (recievedMsg.contains("Is any body out there?")) {
      // sendMessage("I am here!");
      System.out.println("Recieved it!");
      channel.close();
    }
  }
 @Override
 public void receive(Message msg) {
   Object message = msg.getObject();
   if (message instanceof JoinMessage) {
     processJoinMessage(msg, (JoinMessage) message);
   } else if (message instanceof DispatchMessage) {
     processDispatchMessage(msg, (DispatchMessage) message);
   } else if (message instanceof ReplyMessage) {
     processReplyMessage((ReplyMessage) message);
   }
 }
 protected void receive(Message msg) {
   String greeting = (String) msg.getObject();
   msgs.add(greeting);
   System.out.println("received " + greeting + " from " + msg.getSrc());
   if (HELLO1.equals(greeting)) {
     try {
       a.send(new Message(a.getAddress(), HELLO2));
     } catch (Exception e) {
       ex = e;
     }
   }
 }
Пример #11
0
    public void receive(Message msg) {
      Address addr = msg.getSrc();
      Long val = (Long) msg.getObject();

      Collection<Long> list = msgs.get(addr);
      if (list == null) {
        list = new ConcurrentLinkedQueue<Long>();
        Collection<Long> tmp = msgs.putIfAbsent(addr, list);
        if (tmp != null) list = tmp;
      }
      list.add(val);
    }
Пример #12
0
 /** {@inheritDoc} */
 @Override
 public void receive(final Message message) {
   final String msg = (String) message.getObject();
   if (message.getSrc() != jchannel.getLocalAddress()) {
     if (msg != null) {
       receivedMessages.offer(msg);
       if (bc != null) {
         bc.broadcast(msg);
       }
     }
   }
 }
Пример #13
0
  /**
   * Message contains MethodCall. Execute it against *this* object and return result. Use
   * MethodCall.invoke() to do this. Return result.
   */
  public Object handle(Message req) {
    Object body;
    MethodCall method_call;

    if (server_obj == null) {
      if (log.isErrorEnabled()) log.error("no method handler is registered. Discarding request.");
      return null;
    }

    if (req == null || req.getLength() == 0) {
      if (log.isErrorEnabled()) log.error("message or message buffer is null");
      return null;
    }

    try {
      body =
          req_marshaller != null
              ? req_marshaller.objectFromByteBuffer(
                  req.getBuffer(), req.getOffset(), req.getLength())
              : req.getObject();
    } catch (Throwable e) {
      if (log.isErrorEnabled()) log.error("exception marshalling object", e);
      return e;
    }

    if (!(body instanceof MethodCall)) {
      if (log.isErrorEnabled()) log.error("message does not contain a MethodCall object");

      // create an exception to represent this and return it
      return new IllegalArgumentException("message does not contain a MethodCall object");
    }

    method_call = (MethodCall) body;

    try {
      if (log.isTraceEnabled())
        log.trace("[sender=" + req.getSrc() + "], method_call: " + method_call);

      if (method_call.getMode() == MethodCall.ID) {
        if (method_lookup == null)
          throw new Exception(
              "MethodCall uses ID=" + method_call.getId() + ", but method_lookup has not been set");
        Method m = method_lookup.findMethod(method_call.getId());
        if (m == null) throw new Exception("no method found for " + method_call.getId());
        method_call.setMethod(m);
      }

      return method_call.invoke(server_obj);
    } catch (Throwable x) {
      return x;
    }
  }
Пример #14
0
    public void receive(Message msg) {
      if (!msg.isFlagSet(Message.OOB)) {
        try {
          System.out.println(Thread.currentThread() + ": waiting on latch");
          latch.await(25000, TimeUnit.MILLISECONDS);
          System.out.println(Thread.currentThread() + ": DONE waiting on latch");
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }

      msgs.add((Integer) msg.getObject());
    }
 public Object down(Event evt) {
   switch (evt.getType()) {
     case Event.MSG:
       Message msg = (Message) evt.getArg();
       NakAckHeader2 hdr = (NakAckHeader2) msg.getHeader(ID);
       if (hdr == null) break;
       if (hdr.getType() == NakAckHeader2.XMIT_REQ) {
         SeqnoList seqnos = (SeqnoList) msg.getObject();
         System.out.println("-- XMIT-REQ: request retransmission for " + seqnos);
         for (Long seqno : seqnos) xmit_requests.add(seqno);
       }
       break;
   }
   return null;
 }
Пример #16
0
  public Object up(Event evt) {
    Message msg;
    Address dst, src;
    Unicast2Header hdr;

    switch (evt.getType()) {
      case Event.MSG:
        msg = (Message) evt.getArg();
        dst = msg.getDest();

        if (dst == null || msg.isFlagSet(Message.NO_RELIABILITY)) // only handle unicast messages
        break; // pass up

        // changed from removeHeader(): we cannot remove the header because if we do loopback=true
        // at the
        // transport level, we will not have the header on retransmit ! (bela Aug 22 2006)
        hdr = (Unicast2Header) msg.getHeader(this.id);
        if (hdr == null) break;
        src = msg.getSrc();
        switch (hdr.type) {
          case Unicast2Header.DATA: // received regular message
            handleDataReceived(src, hdr.seqno, hdr.conn_id, hdr.first, msg, evt);
            return null; // we pass the deliverable message up in handleDataReceived()
          case Unicast2Header.XMIT_REQ: // received ACK for previously sent message
            handleXmitRequest(src, (SeqnoList) msg.getObject());
            break;
          case Unicast2Header.SEND_FIRST_SEQNO:
            handleResendingOfFirstMessage(src, hdr.seqno);
            break;
          case Unicast2Header.STABLE:
            stable(msg.getSrc(), hdr.conn_id, hdr.seqno, hdr.high_seqno);
            break;
          default:
            log.error("UnicastHeader type " + hdr.type + " not known !");
            break;
        }
        return null;
    }

    return up_prot.up(evt); // Pass up to the layer above us
  }
Пример #17
0
  public Object up(Event evt) {
    switch (evt.getType()) {
      case Event.MSG:
        Message msg = (Message) evt.getArg();
        StateHeader hdr = (StateHeader) msg.getHeader(this.id);
        if (hdr == null) break;

        switch (hdr.type) {
          case StateHeader.STATE_REQ:
            state_requesters.add(msg.getSrc());
            break;
          case StateHeader.STATE_RSP:
            handleStateRsp(hdr.getDigest(), msg.getSrc(), msg.getBuffer());
            break;
          case StateHeader.STATE_EX:
            closeHoleFor(msg.getSrc());
            handleException((Throwable) msg.getObject());
            break;
          default:
            log.error("%s: type %s not known in StateHeader", local_addr, hdr.type);
            break;
        }
        return null;

      case Event.TMP_VIEW:
      case Event.VIEW_CHANGE:
        handleViewChange((View) evt.getArg());
        break;

      case Event.CONFIG:
        Map<String, Object> config = (Map<String, Object>) evt.getArg();
        if (config != null && config.containsKey("state_transfer"))
          log.error(
              Util.getMessage(
                  "ProtocolStackCannotContainTwoStateTransferProtocolsRemoveEitherOneOfThem"));
        break;
    }
    return up_prot.up(evt);
  }
Пример #18
0
    public void run() {
      Object tmp;
      Message msg = null;
      int counter = 0;
      Vector v = new Vector();
      while (running) {
        Util.sleep(10);
        try {

          tmp = channel.receive(0);
          if (tmp == null) continue;

          if (tmp instanceof View) {
            View vw = (View) tmp;
            control.viewNumber.setText(String.valueOf(vw.getVid().getId()));
            control.numMessagesInLastView.setText(String.valueOf(counter));
            counter = 0;
            v.clear();
            continue;
          }

          if (!(tmp instanceof Message)) continue;

          msg = (Message) tmp;

          measureThrougput(msg.size());
          TotalPayload p = null;

          p = (TotalPayload) msg.getObject();
          v.addElement(new Integer(p.getRandomSequence()));
          int size = v.size();
          if (size % 50 == 0) {
            int value = 0;
            int i = 0;
            Iterator iter = v.iterator();
            while (iter.hasNext()) {
              i++;
              int seq = ((Integer) iter.next()).intValue();
              if (i % 2 == 0) {
                value *= seq;
              } else if (i % 3 == 0) {
                value -= seq;
              } else value += seq;
            }
            v.clear();
            value = Math.abs(value);
            int r = value % 85;
            int g = value % 170;
            int b = value % 255;
            colorPanel.setSeq(r, g, b);
          }
          counter++;
        } catch (ChannelNotConnectedException e) {
          e.printStackTrace();
        } catch (ChannelClosedException e) {
          e.printStackTrace();
        } catch (TimeoutException e) {
          e.printStackTrace();
        }
      }
    }
Пример #19
0
 private static String print(List<Message> list) {
   List<String> tmp = new ArrayList<String>(list.size());
   for (Message msg : list) tmp.add((String) msg.getObject());
   return Util.printListWithDelimiter(tmp, " ");
 }
Пример #20
0
 public void receive(Message msg) {
   Integer val = (Integer) msg.getObject();
   msgs.add(val);
 }
Пример #21
0
 public void receive(Message msg) {
   super.receive(msg);
   System.out.println("-- received " + msg.getObject());
   Util.sleep(sleep_time);
 }
Пример #22
0
 public void receive(Message msg) {
   System.out.println(
       "MyListener #" + id + ": received message from " + msg.getSrc() + ": " + msg.getObject());
 }
Пример #23
0
 public void receive(Message msg) {
   msgs.add((Integer) msg.getObject());
 }
Пример #24
0
 public void receive(Message msg) {
   list.add((Integer) msg.getObject());
   System.out.println(chName + "<-- " + msg.getObject());
 }
Пример #25
0
  public Object up(Message msg) {
    ExecutorHeader hdr = msg.getHeader(id);
    if (hdr == null) return up_prot.up(msg);

    Request req = msg.getObject();
    if (log.isTraceEnabled()) log.trace("[" + local_addr + "] <-- [" + msg.getSrc() + "] " + req);
    switch (req.type) {
      case RUN_REQUEST:
        handleTaskRequest(req.request, (Address) req.object);
        break;
      case CONSUMER_READY:
        handleConsumerReadyRequest(req.request, (Address) req.object);
        break;
      case CONSUMER_UNREADY:
        handleConsumerUnreadyRequest(req.request, (Address) req.object);
        break;
      case CONSUMER_FOUND:
        handleConsumerFoundResponse(req.request, (Address) req.object);
        break;
      case RUN_SUBMITTED:
        RequestWithThread reqWT = (RequestWithThread) req;
        Object objectToRun = reqWT.object;
        Runnable runnable;
        if (objectToRun instanceof Runnable) {
          runnable = (Runnable) objectToRun;
        } else if (objectToRun instanceof Callable) {
          @SuppressWarnings("unchecked")
          Callable<Object> callable = (Callable<Object>) objectToRun;
          runnable = new FutureTask<>(callable);
        } else {
          log.error(
              Util.getMessage("RequestOfType")
                  + req.type
                  + " sent an object of "
                  + objectToRun
                  + " which is invalid");
          break;
        }

        handleTaskSubmittedRequest(runnable, msg.getSrc(), req.request, reqWT.threadId);
        break;
      case RUN_REJECTED:
        // We could make requests local for this, but is it really worth it
        handleTaskRejectedResponse(msg.getSrc(), req.request);
        break;
      case RESULT_SUCCESS:
        handleValueResponse(msg.getSrc(), req.request, req.object);
        break;
      case RESULT_EXCEPTION:
        handleExceptionResponse(msg.getSrc(), req.request, (Throwable) req.object);
        break;
      case INTERRUPT_RUN:
        // We could make requests local for this, but is it really worth it
        handleInterruptRequest(msg.getSrc(), req.request);
        break;
      case CREATE_CONSUMER_READY:
        Owner owner = new Owner((Address) req.object, req.request);
        handleNewConsumer(owner);
        break;
      case CREATE_RUN_REQUEST:
        owner = new Owner((Address) req.object, req.request);
        handleNewRunRequest(owner);
        break;
      case DELETE_CONSUMER_READY:
        owner = new Owner((Address) req.object, req.request);
        handleRemoveConsumer(owner);
        break;
      case DELETE_RUN_REQUEST:
        owner = new Owner((Address) req.object, req.request);
        handleRemoveRunRequest(owner);
        break;
      default:
        log.error(Util.getMessage("RequestOfType") + req.type + " not known");
        break;
    }
    return null;
  }
Пример #26
0
    public void receive(Message msg) {

      Packet packet = (Packet) msg.getObject();
      Address address = msg.getSrc();
      pool.submit(new WorkThread(address, packet));
    }
Пример #27
0
 @Override
 public void receive(Message msg) {
   sLog.info("receive(" + msg + ", " + msg.getObject() + ")");
 }
Пример #28
0
 public void receive(Message msg) {
   Integer val = (Integer) msg.getObject();
   System.out.println(name + ": <-- " + val);
   msgs.add(val);
 }