Ejemplo n.º 1
0
  /**
   * Message listener interface.
   *
   * @param msg message
   */
  public void onMessage(Message msg) {
    try {
      String msgText;
      if (msg instanceof TextMessage) {
        msgText = ((TextMessage) msg).getText();
      } else {
        msgText = msg.toString();
      }

      // System.out.println("Message Received: "+ msgText );
      // ClientTools clientTools = new ClientTools();

      // ClientTools.getRequestAsFile(msgText);
      // DataTools dataTools = new DataTools();
      NonCimDataTools nonCimDataTools = new NonCimDataTools();

      if (!nonCimDataTools.deleteOperation(msgText)) {
        // ClientTools.getDataAsFile(msgText);
        nonCimDataTools.rdfToConsole(msgText);
      }
      // System.out.println("OK");

      if (msgText.equalsIgnoreCase("quit")) {
        synchronized (this) {
          quit = true;
          this.notifyAll(); // Notify main thread to quit
        }
      }
    } catch (JMSException jmse) {
      jmse.printStackTrace();
    }
  }
Ejemplo n.º 2
0
 @Override
 public void onMessageDo(Message msg) throws Exception {
   String type = msg.getStringProperty("type");
   if (ResmMessageListener.TYPE_OBJECT_SYNC.equals(type)) {
     TextMessage text = (TextMessage) msg;
     int id = StringUtil.parseInt(text.getText(), -1);
     logger.debug("接收到同步消息:资源ID=" + text.getText());
     if (id > 0) ServiceManager.getResourceUpdateService().syncResource(id);
   } else if (ResmMessageListener.TYPE_CACHE_ADD.equals(type)) {
     ObjectMessage object = (ObjectMessage) msg;
     String cacheName = msg.getStringProperty("cache");
     CacheableObject obj = (CacheableObject) object.getObject();
     logger.debug("接收到缓存增加消息:" + cacheName + " " + obj.getClass().getName());
     obj.onDeserialize();
     obj.dump();
     CacheManager.addCache(cacheName, obj);
   } else if (ResmMessageListener.TYPE_CACHE_REMOVE.equals(type)) {
     ObjectMessage object = (ObjectMessage) msg;
     String cacheName = msg.getStringProperty("cache");
     CacheableObject obj = (CacheableObject) object.getObject();
     logger.debug("接收到缓存删除消息:" + cacheName + " " + obj.getClass().getName());
     obj.onDeserialize();
     obj.dump();
     CacheManager.removeCache(cacheName, obj);
   } else {
     System.out.println(msg.toString());
   }
 }
  /**
   * Return string representation
   *
   * @return The string
   */
  @Override
  public String toString() {
    if (ActiveMQRAMessage.trace) {
      ActiveMQRALogger.LOGGER.trace("toString()");
    }

    return message.toString();
  }
 /**
  * Unpacks and calls accept() on the message object.
  *
  * <p>This method catches <b>all</b> exceptions and logs them.
  *
  * @param msg a ObjectMessage
  */
 public void onMessage(Message msg) {
   ArgumentNotValid.checkNotNull(msg, "Message msg");
   log.trace("Message received:\n{}", msg.toString());
   try {
     ((ArchiveMessage) JMSConnection.unpack(msg)).accept(this);
   } catch (ClassCastException e) {
     log.warn("Invalid message type", e);
   } catch (Throwable t) {
     log.warn("Error processing message '{}'", msg, t);
   }
 }
Ejemplo n.º 5
0
 public void onMessage(Message message) {
   if (message instanceof TextMessage) {
     try {
       logger.info("Recieved text in listener: " + ((TextMessage) message).getText());
     } catch (JMSException e) {
       logger.error("", e);
       throw new RuntimeException(e);
     }
   } else {
     throw new RuntimeException(" ~~~ Error in format ~~~ : " + message.toString());
   }
 }
Ejemplo n.º 6
0
  @Override
  public void run() {
    while (true) {
      try {
        // Wait for a message
        Message message = consumer.receive();
        if (message instanceof TextMessage) {
          TextMessage textMessage = (TextMessage) message;
          String text = textMessage.getText();

          chatPanel.updateChatWindow(text);

        } else {
          chatPanel.updateChatWindow(message.toString());
        }
      } catch (Exception e) {
        LOG.error(e);
      }
    }
  }
  @SuppressWarnings("unchecked")
  public void onMessage(Message message) {
    log.debug("Receiving a message on {} : {}", SyncJMSMessageProducer.QUEUE_NAME, message);
    try {

      String topic = message.getJMSType();
      String groupId = (String) message.getStringProperty("path");

      String operation = "UNKNOWN";

      // A group was DELETED
      if ("org/sakaiproject/nakamura/lite/authorizables/DELETE".equals(topic)
          && config.getDeletesEnabled()) {
        Map<String, Object> attributes =
            (Map<String, Object>) message.getObjectProperty(StoreListener.BEFORE_EVENT_PROPERTY);
        grouperManager.deleteGroup(groupId, attributes);
        operation = "DELETED";
      }

      // A new group was ADDED or an existing group was UPDATED
      if ("org/sakaiproject/nakamura/lite/authorizables/ADDED".equals(topic)
          || "org/sakaiproject/nakamura/lite/authorizables/UPDATED".equals(topic)) {
        // These events should be under org/sakaiproject/nakamura/lite/authorizables/UPDATED
        // http://jira.sakaiproject.org/browse/KERN-1795
        String membersAdded =
            (String) message.getStringProperty(GrouperEventUtils.MEMBERS_ADDED_PROP);
        if (membersAdded != null) {
          // membership adds can be attached to the same event for the group add.
          grouperManager.createGroup(groupId, config.getGroupTypes());
          grouperManager.addMemberships(
              groupId, Arrays.asList(StringUtils.split(membersAdded, ",")));
          operation = "ADD_MEMBERS";
        }

        String membersRemoved =
            (String) message.getStringProperty(GrouperEventUtils.MEMBERS_REMOVED_PROP);
        if (membersRemoved != null) {
          grouperManager.removeMemberships(
              groupId, Arrays.asList(StringUtils.split(membersRemoved, ",")));
          operation = "REMOVE_MEMBERS";
        }

        if (membersAdded == null && membersRemoved == null) {
          org.sakaiproject.nakamura.api.lite.Session repositorySession =
              repository.loginAdministrative();
          AuthorizableManager am = repositorySession.getAuthorizableManager();
          Group group = (Group) am.findAuthorizable(groupId);
          repositorySession.logout();

          if (groupId.startsWith(ContactsGrouperNameProviderImpl.CONTACTS_GROUPID_PREFIX)) {
            // TODO Why are we not getting added and removed properties on the Message
            grouperManager.createGroup(groupId, null);
            grouperManager.addMemberships(groupId, Arrays.asList(group.getMembers()));
            operation = "UPDATE CONTACTS";
          } else {
            grouperManager.createGroup(groupId, config.getGroupTypes());
            grouperManager.addMemberships(groupId, Arrays.asList(group.getMembers()));
            operation = "CREATE";
          }
        }
      }

      // The message was processed successfully. No exceptions were thrown.
      // We acknowledge the message and its removed from the queue
      message.acknowledge();

      // We got a message that we didn't know what to do with.
      if (operation.equals("UNKNOWN")) {
        log.error(
            "I don't know what to do with this topic: {}. Turn on debug logs to see the message.",
            topic);
        log.debug(message.toString());
      } else {
        log.info("Successfully processed and acknowledged. {}, {}", operation, groupId);
        log.debug(message.toString());
      }

    } catch (JMSException jmse) {
      log.error("JMSException while processing message.", jmse);
    } catch (Exception e) {
      log.error("Exception while processing message.", e);
    }
  }
Ejemplo n.º 8
0
 @Override
 public void onMessage(Message message) {
   this.printOutMessage(message.toString());
 }