public void receive(Message message) throws MessageListenerException {
    String destinationName =
        GetterUtil.getString(message.getString(SchedulerEngine.DESTINATION_NAME));

    if (destinationName.equals(DestinationNames.SCHEDULER_DISPATCH)) {
      String receiverKey = GetterUtil.getString(message.getString(SchedulerEngine.RECEIVER_KEY));

      if (!receiverKey.equals(_key)) {
        return;
      }
    }

    try {
      _messageListener.receive(message);
    } catch (Exception e) {
      handleException(message, e);

      if (e instanceof MessageListenerException) {
        throw (MessageListenerException) e;
      } else {
        throw new MessageListenerException(e);
      }
    } finally {
      if (message.getBoolean(SchedulerEngine.DISABLE)
          && destinationName.equals(DestinationNames.SCHEDULER_DISPATCH)) {

        MessageBusUtil.unregisterMessageListener(destinationName, this);
      }
    }
  }
  protected void registerMessageListeners(String destinationName, Message message)
      throws SchedulerException {

    if (_portletLocalService == null) {
      throw new IllegalStateException("Portlet local service not initialized");
    }

    String messageListenerClassName =
        message.getString(SchedulerEngine.MESSAGE_LISTENER_CLASS_NAME);

    if (Validator.isNull(messageListenerClassName)) {
      return;
    }

    String portletId = message.getString(SchedulerEngine.PORTLET_ID);

    ClassLoader classLoader = null;

    if (Validator.isNull(portletId)) {
      classLoader = PortalClassLoaderUtil.getClassLoader();
    } else {
      Portlet portlet = _portletLocalService.getPortletById(portletId);

      if (portlet == null) {

        // No portlet found for the portlet ID. Try getting the class
        // loader where we assume the portlet ID is actually a servlet
        // context name.

        classLoader = ClassLoaderPool.getClassLoader(portletId);
      } else {
        PortletApp portletApp = portlet.getPortletApp();

        ServletContext servletContext = portletApp.getServletContext();

        classLoader = servletContext.getClassLoader();
      }
    }

    if (classLoader == null) {
      throw new SchedulerException("Unable to find class loader for portlet " + portletId);
    }

    MessageListener schedulerEventListener =
        getMessageListener(messageListenerClassName, classLoader);

    SchedulerEventMessageListenerWrapper schedulerEventListenerWrapper =
        new SchedulerEventMessageListenerWrapper();

    schedulerEventListenerWrapper.setMessageListener(schedulerEventListener);

    schedulerEventListenerWrapper.afterPropertiesSet();

    _messageBus.registerMessageListener(destinationName, schedulerEventListenerWrapper);

    message.put(
        SchedulerEngine.MESSAGE_LISTENER_UUID,
        schedulerEventListenerWrapper.getMessageListenerUUID());
  }
  @Override
  protected void doReceive(Message message) throws Exception {
    String command = message.getString("command");
    String servletContextName = message.getString("servletContextName");

    if (command.equals("undeploy") && servletContextName.equals(getServletContextName())) {
      UserNoteLocalServiceUtil.clearService();
    }
  }
  protected void doReceive(Message message) throws Exception {
    String command = message.getString("command");
    String servletContextName = message.getString("servletContextName");

    if (command.equals("undeploy") && servletContextName.equals(SERVLET_CONTEXT_NAME)) {
      RuleLocalServiceUtil.clearService();

      RuleServiceUtil.clearService();
    }
  }
  protected void unregisterMessageListener(Scheduler scheduler, JobKey jobKey) throws Exception {

    JobDetail jobDetail = scheduler.getJobDetail(jobKey);

    if (jobDetail == null) {
      return;
    }

    JobDataMap jobDataMap = jobDetail.getJobDataMap();

    if (jobDataMap == null) {
      return;
    }

    Message message = getMessage(jobDataMap);

    String messageListenerUUID = message.getString(SchedulerEngine.MESSAGE_LISTENER_UUID);

    if (messageListenerUUID == null) {
      return;
    }

    String destinationName = jobDataMap.getString(SchedulerEngine.DESTINATION_NAME);

    Destination destination = _messageBus.getDestination(destinationName);

    if (destination == null) {
      return;
    }

    Set<MessageListener> messageListeners = destination.getMessageListeners();

    for (MessageListener messageListener : messageListeners) {
      if (!(messageListener instanceof InvokerMessageListener)) {
        continue;
      }

      InvokerMessageListener invokerMessageListener = (InvokerMessageListener) messageListener;

      messageListener = invokerMessageListener.getMessageListener();

      if (!(messageListener instanceof SchedulerEventMessageListenerWrapper)) {

        continue;
      }

      SchedulerEventMessageListenerWrapper schedulerMessageListener =
          (SchedulerEventMessageListenerWrapper) messageListener;

      if (messageListenerUUID.equals(schedulerMessageListener.getMessageListenerUUID())) {

        _messageBus.unregisterMessageListener(destinationName, schedulerMessageListener);

        return;
      }
    }
  }
  @Override
  protected void doReceive(Message message) throws Exception {
    String command = message.getString(MESSAGE_KEY_COMMAND);

    if (command.equals(COMMAND_ON_AFTER_DEPLOY)
        || command.equals(COMMAND_ON_AFTER_REDEPLOY)
        || command.equals(COMMAND_ON_AFTER_UNDEPLOY)
        || command.equals(COMMAND_ON_BEFORE_DEPLOY)
        || command.equals(COMMAND_ON_BEFORE_REDEPLOY)
        || command.equals(COMMAND_ON_BEFORE_UNDEPLOY)) {

      process(message, command);
    }
  }
Пример #7
0
  @Override
  protected void doReceive(Message message) throws Exception {
    String command = message.getString("command");
    String servletContextName = message.getString("servletContextName");

    if (command.equals("undeploy") && servletContextName.equals(getServletContextName())) {
      EDDepartmentLocalServiceUtil.clearService();

      EDDepartmentServiceUtil.clearService();
      EDEmployeeLocalServiceUtil.clearService();

      EDEmployeeServiceUtil.clearService();
      EDFunctionLocalServiceUtil.clearService();

      EDFunctionServiceUtil.clearService();
      EDFunctionDepartmentLocalServiceUtil.clearService();

      EDFunctionDepartmentServiceUtil.clearService();
      EDFunctionEmployeeLocalServiceUtil.clearService();

      EDFunctionEmployeeServiceUtil.clearService();
    }
  }