public void readInternal(DataInput in) throws IOException {
   name = in.readUTF();
   int targetBytesLength = in.readInt();
   byte[] targetBytes = new byte[targetBytesLength];
   in.readFully(targetBytes);
   this.target = (ActorRef) Util.toObject(targetBytes);
 }
  public void dispatch(
      Object target, Object msg, Object sender, MissingMethodHandler missingMethodHandler)
      throws Exception {
    notNull(target, "target");

    Class targetClass = target.getClass();

    Method receiveMethod = findReceiveMethod(targetClass, msg.getClass());
    if (receiveMethod == null) {
      missingMethodHandler.onUnhandledMessage(msg, sender);
      return;
    }

    try {
      if (receiveMethod.getParameterTypes().length == 2) {
        receiveMethod.invoke(target, msg, sender);
      } else {
        receiveMethod.invoke(target, msg);
      }
    } catch (IllegalAccessException e) {
      // This will not be thrown since we make the receiveMethod accessible
      throw new RuntimeException(e);
    } catch (InvocationTargetException e) {
      throw Util.handle(e);
    }
  }
 public void writeInternal(DataOutput out) throws IOException {
   out.writeUTF(name);
   byte[] targetBytes = Util.toBytes(target);
   out.writeInt(targetBytes.length);
   out.write(targetBytes);
 }