예제 #1
0
  @Override
  public void deactivate() {
    super.deactivate();
    ((PropertiesChangeSupport) getModel()).removePropertyChangeListener(this);
    SharedThreadPool.getInstance()
        .execute(
            new Runnable() {

              @Override
              @TaskDescription("Clear workflow node in validation support.")
              public void run() {
                validationSupport.setWorkflowNodeAndValidation(null);
              }
            });
  }
  /**
   * Implementation of the OSGi {@link LogListener} interface that asynchronously forwards each
   * event to a given {@link SerializableLogListener}.
   *
   * @author Robert Mischke
   */
  private final class SingleReceiverOsgiLogForwarder implements LogListener {

    private static final String ASYNC_TASK_DESCRIPTION = "Forward log event to listener";

    private final SerializableLogListener externalListener;

    // TODO review exception policy; which is better?
    private final AsyncOrderedExecutionQueue orderedExecutionQueue =
        new AsyncOrderedExecutionQueue(
            AsyncCallbackExceptionPolicy.LOG_AND_CANCEL_LISTENER, SharedThreadPool.getInstance());

    private SingleReceiverOsgiLogForwarder(SerializableLogListener externalListener) {
      this.externalListener = externalListener;
    }

    @Override
    public void logged(final LogEntry entry) {

      if (entry.getLevel() == LogService.LOG_DEBUG) {
        return;
      }
      orderedExecutionQueue.enqueue(
          new Runnable() {

            @Override
            @TaskDescription(ASYNC_TASK_DESCRIPTION)
            public void run() {
              try {
                String exceptionString = "";
                if (entry.getException() != null) {
                  exceptionString = entry.getException().toString();
                }
                externalListener.logged(
                    new SerializableLogEntry(
                        entry.getBundle().getSymbolicName(),
                        entry.getLevel(),
                        entry.getMessage().replaceAll("\n", SerializableLogEntry.RCE_SEPARATOR),
                        entry.getTime(),
                        exceptionString));
              } catch (RemoteOperationException e) {
                final Log localLog = LogFactory.getLog(getClass());
                localLog.error(
                    "Error while forwarding log event to listener "
                        + "(delivery of log events to this receiver will be cancelled): "
                        + e.toString());
                // TODO >7.0.0: these lines should be equivalent, but aren't; investigate why -
                // misc_ro, Nov 2015
                // orderedExecutionQueue.cancelAsync();
                throw new RuntimeException(
                    "Error while forwarding log event to listener"); // workaround to restore
                // behavior
              }
              // the @TaskDescription is not forwarded by AsyncOrderedExecutionQueue, so count a
              // stats event for monitoring - misc_ro
              StatsCounter.count(
                  AsyncOrderedExecutionQueue.STATS_COUNTER_SHARED_CATEGORY_NAME,
                  ASYNC_TASK_DESCRIPTION);
            }
          });
    }

    public void shutdown() {
      orderedExecutionQueue.cancelAsync();
    }
  }