public Object send() throws MessageBusException {
    String destinationName = _message.getDestinationName();
    String responseDestinationName = _message.getResponseDestinationName();

    _messageBus.registerMessageListener(responseDestinationName, this);

    try {
      _messageBus.sendMessage(destinationName, _message);

      _countDownLatch.await(_timeout, TimeUnit.MILLISECONDS);

      if (_results == null) {
        throw new MessageBusException("No reply received for message: " + _message);
      }

      return _results;
    } catch (InterruptedException ie) {
      throw new MessageBusException("Message sending interrupted for: " + _message, ie);
    } finally {
      _messageBus.unregisterMessageListener(responseDestinationName, this);

      _entityCache.clearLocalCache();
      _finderCache.clearLocalCache();
      ThreadLocalCacheManager.destroy();
    }
  }
  @Override
  protected void doReceive(Object messagePayload, Address srcAddress) {
    ClusterChannel clusterChannel = _clusterExecutorImpl.getClusterChannel();

    if (srcAddress.equals(clusterChannel.getLocalAddress())) {
      return;
    }

    try {
      if (messagePayload instanceof ClusterRequest) {
        ClusterRequest clusterRequest = (ClusterRequest) messagePayload;

        Serializable responsePayload =
            _clusterExecutorImpl.handleReceivedClusterRequest(clusterRequest);

        if (clusterRequest.isFireAndForget()) {
          return;
        }

        try {
          clusterChannel.sendUnicastMessage(responsePayload, srcAddress);
        } catch (Throwable t) {
          _log.error("Unable to send message " + responsePayload, t);
        }
      } else if (messagePayload instanceof ClusterNodeResponse) {
        _clusterExecutorImpl.handleReceivedClusterNodeResponse(
            (ClusterNodeResponse) messagePayload);
      } else if (_log.isWarnEnabled()) {
        _log.warn("Unable to process message content of type " + messagePayload.getClass());
      }
    } finally {
      ThreadLocalCacheManager.clearAll(Lifecycle.REQUEST);

      CentralizedThreadLocal.clearShortLivedThreadLocals();
    }
  }
예제 #3
0
  @Override
  public void init() throws ServletException {
    if (_log.isDebugEnabled()) {
      _log.debug("Initialize");
    }

    ServletContext servletContext = getServletContext();

    servletContext.setAttribute(SlimRuntimeServlet.class.getName(), Boolean.TRUE);

    super.init();

    if (_log.isDebugEnabled()) {
      _log.debug("Process startup events");
    }

    try {
      processStartupEvents();
    } catch (Exception e) {
      _log.error(e, e);

      System.out.println("Stopping the server due to unexpected startup errors");

      if (e instanceof ServletException) {
        throw (ServletException) e;
      }

      throw new ServletException(e);
    }

    servletContext.setAttribute(WebKeys.STARTUP_FINISHED, true);

    registerPortalInitialized();

    ThreadLocalCacheManager.clearAll(Lifecycle.REQUEST);
  }
  @Override
  public void onAfterRemoveAssociation(
      Object classPK, String associationClassName, Object associationClassPK)
      throws ModelListenerException {

    try {
      User user = userLocalService.getUser((Long) classPK);

      FinderCacheUtil.clearCache(_MAPPING_TABLE_USERS_ROLES_NAME_LEFT_TO_RIGHT);
      FinderCacheUtil.clearCache(_MAPPING_TABLE_USERS_ROLES_NAME_RIGHT_TO_LEFT);

      ThreadLocalCacheManager.clearAll(Lifecycle.REQUEST);

      if (userLocalService.hasRoleUser(
          user.getCompanyId(), RoleConstants.SOCIAL_OFFICE_USER, user.getUserId(), true)) {

        return;
      }

      if (associationClassName.equals(Group.class.getName())
          || associationClassName.equals(Organization.class.getName())
          || associationClassName.equals(UserGroup.class.getName())) {

        Role role = roleLocalService.getRole(user.getCompanyId(), RoleConstants.SOCIAL_OFFICE_USER);

        Group group = null;

        if (associationClassName.equals(Group.class.getName())) {
          group = groupLocalService.getGroup((Long) associationClassPK);
        } else if (associationClassName.equals(Organization.class.getName())) {

          group =
              groupLocalService.getOrganizationGroup(
                  user.getCompanyId(), (Long) associationClassPK);
        } else if (associationClassName.equals(UserGroup.class.getName())) {

          group =
              groupLocalService.getUserGroupGroup(user.getCompanyId(), (Long) associationClassPK);
        }

        if (groupLocalService.hasRoleGroup(role.getRoleId(), group.getGroupId())) {

          disableSocialOffice(user.getGroup());
        }
      } else if (associationClassName.equals(Role.class.getName())) {
        Role role = roleLocalService.getRole((Long) associationClassPK);

        String name = role.getName();

        if (name.equals(RoleConstants.SOCIAL_OFFICE_USER)) {
          disableSocialOffice(user.getGroup());
        }
      }
    } catch (NoSuchGroupException nsge) {

      // LPS-52675

      if (_log.isDebugEnabled()) {
        _log.debug(nsge, nsge);
      }
    } catch (Exception e) {
      throw new ModelListenerException(e);
    }
  }