/**
   * コンストラクタ メッセージの受信ハンドラを設定する
   *
   * @param string
   */
  public MessengerGWTImplement(String messengerName, Object invokeObject) {
    debug = new Debug(this);

    this.messengerName = messengerName;
    this.messengerID = UUID.uuid(8, 16);
    this.invokeObject = invokeObject;

    parentName = "";
    parentID = "";

    sendList = new ArrayList<JSONObject>();
    receiveList = new ArrayList<JSONObject>();

    childList = new ArrayList<JSONObject>();

    postMessageAPIMethod = get(this);

    if (MessageMasterHub.getMaster().getMessengerGlobalStatus()
        == MESSENGER_STATUS_READY_FOR_INITIALIZE) {
      int status = setUp(postMessageAPIMethod); // Java-method to JavaScriptObject(as function)

      debug.assertTrue(
          MessageMasterHub.getMaster().getMessengerGlobalStatus()
              == MESSENGER_STATUS_READY_FOR_INITIALIZE,
          "already initialized");
      MessageMasterHub.getMaster().setMessengerGlobalStatus(status);
    }

    MessageMasterHub.getMaster().setInvokeObject(this);
  }
 /**
  * EventBus実装での同期メッセージング 同期メッセージを自分へと送信するメソッド 自分へのメッセージング
  *
  * @param command
  * @param tagValue
  */
 public void sCallMyself(String command, JSONObject... tagValue) {
   JSONObject messageMap =
       getMessageStructure(
           MS_CATEGOLY_LOCAL,
           UUID.uuid(8, 16),
           getName(),
           getID(),
           getName(),
           getID(),
           command,
           tagValue);
   MessageMasterHub.getMaster().syncMessage(messageMap.toString());
   addSendLog(messageMap);
 }
  /**
   * 親子関係の構築を行う
   *
   * @param input
   */
  public void inputParent(String inputName) {
    debug.assertTrue(parentName.equals(""), "already have parentName	すでに先約があるようです");
    debug.assertTrue(parentID.equals(""), "already have parentID	すでに先約があるようです");

    debug.assertTrue(!inputName.equals(""), "空文字は親の名称として指定できません");

    parentName = inputName;

    String messageID = UUID.uuid(8, 16);
    JSONObject messageMap =
        getMessageStructure(
            MS_CATEGOLY_PARENTSEARCH, messageID, getName(), getID(), inputName, "", "");
    sendAsyncMessage(messageMap);
  }
 /**
  * 非同期メッセージを自分へと送信するメソッド 自分へのメッセージング
  *
  * @param command
  * @param tagValue
  */
 public String callMyself(String command, JSONObject... tagValue) {
   String messageID = UUID.uuid(8, 16);
   JSONObject messageMap =
       getMessageStructure(
           MS_CATEGOLY_LOCAL,
           messageID,
           getName(),
           getID(),
           getName(),
           getID(),
           command,
           tagValue);
   sendAsyncMessage(messageMap);
   return messageID;
 }
 /**
  * 送付前のメッセージのプレビューを取得するメソッド
  *
  * @param receiverName
  * @param command
  * @param tagValue
  * @return
  */
 public JSONObject getMessageObjectPreview(
     int messageCategoly,
     String receiverName,
     String receiverID,
     String command,
     JSONObject... tagValue) {
   return getMessageStructure(
       messageCategoly,
       UUID.uuid(8, 16),
       getName(),
       getID(),
       receiverName,
       receiverID,
       command,
       tagValue);
 }
  /**
   * EventBus実装での同期メッセージング 同期メッセージを親へと送信するメソッド 親へのメッセージング
   *
   * @param command
   * @param tagValue
   */
  public void sCallParent(String command, JSONObject... tagValue) {
    debug.assertTrue(parentName != "", "SYNC	parentName not applied yet");
    debug.assertTrue(parentID != "", "SYNC	parentID not applied yet");

    JSONObject messageMap =
        getMessageStructure(
            MS_CATEGOLY_CALLPARENT,
            UUID.uuid(8, 16),
            getName(),
            getID(),
            getParentName(),
            getParentID(),
            command,
            tagValue);
    MessageMasterHub.getMaster().syncMessage(messageMap.toString());
    addSendLog(messageMap);
  }
 /**
  * EventBus実装での同期メッセージング イベントでの実装が、他と同レベルなコンテキストに書かれてしまう事が、どうしても欠点として映る。
  *
  * @param toName
  * @param command
  * @param tagValue
  */
 public void sCall(String toName, String command, JSONObject... tagValue) {
   for (JSONObject currentChild : childList) {
     if (currentChild.get(CHILDLIST_KEY_CHILD_NAME).isString().stringValue().equals(toName)) {
       String toID = currentChild.get(CHILDLIST_KEY_CHILD_ID).isString().stringValue();
       JSONObject messageMap =
           getMessageStructure(
               MS_CATEGOLY_CALLCHILD,
               UUID.uuid(8, 16),
               getName(),
               getID(),
               toName,
               toID,
               command,
               tagValue);
       MessageMasterHub.getMaster().syncMessage(messageMap.toString());
       addSendLog(messageMap);
     }
   }
 }
  /**
   * 非同期メッセージを親へと送信するメソッド 親へのメッセージング
   *
   * @param command
   * @param tagValue
   */
  public String callParent(String command, JSONObject... tagValue) {
    debug.assertTrue(parentName != "", "ASYNC parentName not applied yet");
    debug.assertTrue(parentID != "", "ASYNC	parentID not applied yet");

    String messageID = UUID.uuid(8, 16);
    JSONObject messageMap =
        getMessageStructure(
            MS_CATEGOLY_CALLPARENT,
            messageID,
            getName(),
            getID(),
            getParentName(),
            getParentID(),
            command,
            tagValue);
    debug.trace("true	messageMap	" + messageMap.toString());
    sendAsyncMessage(messageMap);
    return messageID;
  }
 /**
  * 非同期メッセージを子供へと送信するメソッド 子供へのメッセージング
  *
  * @param toName
  * @param command
  * @param tagValue
  */
 public void call(String toName, String command, JSONObject... tagValue) {
   //		Window.alert("送る前までは来てる	"+childList);
   for (JSONObject currentChild : childList) {
     //			Window.alert("currentChild	"+currentChild);
     if (currentChild.get(CHILDLIST_KEY_CHILD_NAME).isString().stringValue().equals(toName)) {
       String toID = currentChild.get(CHILDLIST_KEY_CHILD_ID).isString().stringValue();
       JSONObject messageMap =
           getMessageStructure(
               MS_CATEGOLY_CALLCHILD,
               UUID.uuid(8, 16),
               getName(),
               getID(),
               toName,
               toID,
               command,
               tagValue);
       sendAsyncMessage(messageMap);
       //				Window.alert("送った");
     }
   }
 }
  /**
   * PostMessageAPI からダイレクトで複数のmessengerが各個に呼ばれる事を想定したメソッド
   *
   * @param rootMessage
   */
  public void onMessagereceivedFromPostMessageAPI(String rootMessage) {
    JSONObject rootObject = null;
    //		Window.alert("受け取った	"+getName());
    try {
      rootObject = JSONParser.parseStrict(rootMessage).isObject();
    } catch (Exception e) {
      debug.trace("receiveMessage_parseError_" + e);
      return;
    }

    if (rootObject == null) {
      debug.trace("rootObject = null");
      return;
    }

    String toName = null;
    {
      /*
       * 宛先チェック
       */
      debug.assertTrue(rootObject.get(KEY_TO_NAME).isString() != null, "invalid KEY_TO_NAME");
      toName = rootObject.get(KEY_TO_NAME).isString().stringValue();

      if (!toName.equals(getName())) { // 送信者の指定した宛先が自分か
        //			NSLog(@"MS_CATEGOLY_CALLPARENT_宛先ではないMessnegerが受け取った");
        return;
      }
    }

    String fromName = null;
    String fromID = null;
    {
      /*
       * 送付元名前チェック
       */
      fromName = rootObject.get(KEY_MESSENGER_NAME).isString().stringValue();
      debug.assertTrue(fromName != null, "invalid KEY_MESSENGER_NAME");

      /*
       * 送付元IDチェック
       */

      fromID = rootObject.get(KEY_MESSENGER_ID).isString().stringValue();
      debug.assertTrue(fromID != null, "invalid KEY_MESSENGER_ID");
    }

    int categoly;
    {
      debug.assertTrue(
          rootObject.get(KEY_MESSAGE_CATEGOLY).isNumber() != null, "no KEY_MESSAGE_CATEGOLY");
      categoly = (int) rootObject.get(KEY_MESSAGE_CATEGOLY).isNumber().doubleValue();
    }

    /*
     * コマンドチェック
     */
    {
      debug.assertTrue(
          rootObject.get(KEY_MESSENGER_EXEC).isString() != null, "KEY_MESSENGER_EXEC = null");
    }

    /*
     * tag-valueチェック
     */
    {
      debug.assertTrue(
          rootObject.get(KEY_MESSENGER_TAGVALUE_GROUP).isObject() != null,
          "KEY_MESSENGER_TAGVALUE_GROUP = null");
    }

    /*
     * 宛先存在チェック
     */
    String toID = null;
    {
      debug.assertTrue(rootObject.get(KEY_TO_ID).isString() != null, "no KEY_TO_ID");
      toID = rootObject.get(KEY_TO_ID).isString().stringValue();
    }
    //		Window.alert("カテゴリチェックまで	メッセージングを受け取りました");

    switch (categoly) {
      case MS_CATEGOLY_LOCAL:
        {
          if (toID.equals(getID())) {
            addReceiveLog(rootObject);
            receiveCenter(rootMessage);
          }
        }
        return;

      case MS_CATEGOLY_CALLCHILD:
        if (toID.equals(getID())) {
          addReceiveLog(rootObject);
          receiveCenter(rootMessage);
        }
        return;

      case MS_CATEGOLY_CALLPARENT:
        // 宛先MIDが自分のIDと一致するか
        if (toID.equals(getID())) {
          //				Window.alert("親として呼ばれた	メッセージングを受け取りました	");
          addReceiveLog(rootObject);
          receiveCenter(rootMessage);
          //				Window.alert("親として呼ばれた2	メッセージングを受け取りました");
        }

        return;

      case MS_CATEGOLY_PARENTSEARCH:
        debug.assertTrue(rootObject.get(KEY_PARENT_NAME).isString() != null, "no KEY_PARENT_NAME");
        String childSearchingName = rootObject.get(KEY_PARENT_NAME).isString().stringValue();
        if (childSearchingName.equals(getName())) {

          JSONObject childInfo = new JSONObject();
          childInfo.put(CHILDLIST_KEY_CHILD_ID, new JSONString(fromID));
          childInfo.put(CHILDLIST_KEY_CHILD_NAME, new JSONString(fromName));

          childList.add(childInfo);
          //				Window.alert("子供っす	"+childList+"	で、名前が	"+childInfo);
          JSONObject messageMap =
              getMessageStructure(
                  MS_CATEGOLY_PARENTSEARCH_RET,
                  UUID.uuid(8, 16),
                  getName(),
                  getID(),
                  fromName,
                  fromID,
                  TRIGGER_PARENTCONNECTED);
          sendAsyncMessage(messageMap);
          addReceiveLog(rootObject);
        }

        return;

      case MS_CATEGOLY_PARENTSEARCH_S:
        debug.assertTrue(rootObject.get(KEY_PARENT_NAME).isString() != null, "no KEY_PARENT_NAME");
        String childSearchingName2 = rootObject.get(KEY_PARENT_NAME).isString().stringValue();
        if (childSearchingName2.equals(getName())) {
          addReceiveLog(rootObject);
          JSONObject childInfo = new JSONObject();
          childInfo.put(CHILDLIST_KEY_CHILD_ID, new JSONString(fromID));
          childInfo.put(CHILDLIST_KEY_CHILD_NAME, new JSONString(fromName));

          childList.add(childInfo);

          JSONObject messageMap =
              getMessageStructure(
                  MS_CATEGOLY_PARENTSEARCH_RET,
                  UUID.uuid(8, 16),
                  getName(),
                  getID(),
                  fromName,
                  fromID,
                  TRIGGER_PARENTCONNECTED);
          MessageMasterHub.getMaster().syncMessage(messageMap.toString());
          addSendLog(messageMap);
        }
        break;

      case MS_CATEGOLY_PARENTSEARCH_RET:
        if (!parentName.equals(fromName)) {
          return;
        }

        if (toID.equals(getID())) {
          if (parentID.equals("")) {
            parentID = fromID;
            addReceiveLog(rootObject);
          } else {
            //					debug.trace("もう別の親が居ます"+ "/fromID	"+fromID);
          }
        }

        return;

      case MS_CATEGOLY_REMOVE_CHILD:
      case MS_CATEGOLY_REMOVE_PARENT:
      default:
        debug.assertTrue(false, "not ready yet or UNKNOWN CATEGOLY");
        return;
    }
  }