Java 类com.intellij.util.messages.Topic 实例源码

项目:intellij-ce-playground    文件:MessageBusImpl.java   
@Override
@NotNull
@SuppressWarnings({"unchecked"})
public <L> L syncPublisher(@NotNull final Topic<L> topic) {
  checkNotDisposed();
  L publisher = (L)mySyncPublishers.get(topic);
  if (publisher == null) {
    final Class<L> listenerClass = topic.getListenerClass();
    InvocationHandler handler = new InvocationHandler() {
      @Override
      public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        sendMessage(new Message(topic, method, args));
        return NA;
      }
    };
    publisher = (L)Proxy.newProxyInstance(listenerClass.getClassLoader(), new Class[]{listenerClass}, handler);
    publisher = (L)ConcurrencyUtil.cacheOrGet(mySyncPublishers, topic, publisher);
  }
  return publisher;
}
项目:intellij-ce-playground    文件:MessageBusImpl.java   
@Override
@NotNull
@SuppressWarnings({"unchecked"})
public <L> L asyncPublisher(@NotNull final Topic<L> topic) {
  checkNotDisposed();
  L publisher = (L)myAsyncPublishers.get(topic);
  if (publisher == null) {
    final Class<L> listenerClass = topic.getListenerClass();
    InvocationHandler handler = new InvocationHandler() {
      @Override
      public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        postMessage(new Message(topic, method, args));
        return NA;
      }
    };
    publisher = (L)Proxy.newProxyInstance(listenerClass.getClassLoader(), new Class[]{listenerClass}, handler);
    publisher = (L)ConcurrencyUtil.cacheOrGet(myAsyncPublishers, topic, publisher);
  }
  return publisher;
}
项目:intellij-ce-playground    文件:MessageBusImpl.java   
private void calcSubscribers(Topic topic, List<MessageBusConnectionImpl> result) {
  final List<MessageBusConnectionImpl> topicSubscribers = mySubscribers.get(topic);
  if (topicSubscribers != null) {
    result.addAll(topicSubscribers);
  }

  Topic.BroadcastDirection direction = topic.getBroadcastDirection();

  if (direction == Topic.BroadcastDirection.TO_CHILDREN) {
    for (MessageBusImpl childBus : myChildBuses) {
      childBus.calcSubscribers(topic, result);
    }
  }

  if (direction == Topic.BroadcastDirection.TO_PARENT && myParentBus != null) {
    myParentBus.calcSubscribers(topic, result);
  }
}
项目:intellij-ce-playground    文件:MessageBusImpl.java   
private void postMessage(Message message) {
  checkNotDisposed();
  final Topic topic = message.getTopic();
  List<MessageBusConnectionImpl> topicSubscribers = mySubscriberCache.get(topic);
  if (topicSubscribers == null) {
    topicSubscribers = new SmartList<MessageBusConnectionImpl>();
    calcSubscribers(topic, topicSubscribers);
    mySubscriberCache.put(topic, topicSubscribers);
  }
  if (!topicSubscribers.isEmpty()) {
    for (MessageBusConnectionImpl subscriber : topicSubscribers) {
      subscriber.getBus().myMessageQueue.get().offer(new DeliveryJob(subscriber, message));
      subscriber.getBus().notifyPendingJobChange(1);
      subscriber.scheduleMessageDelivery(message);
    }
  }
}
项目:intellij-haskforce    文件:HaskellToolsConfigurable.java   
Tool(Project project, String command, ToolKey key, TextFieldWithBrowseButton pathField,
     RawCommandLineEditor flagsField, JButton autoFindButton, JTextField versionField, String versionParam,
     @Nullable Topic<SettingsChangeNotifier> topic) {
    this.project = project;
    this.command = command;
    this.key = key;
    this.pathField = pathField;
    this.flagsField = flagsField;
    this.versionField = versionField;
    this.versionParam = versionParam;
    this.autoFindButton = autoFindButton;
    this.topic = topic;
    this.publisher = topic == null ? null : project.getMessageBus().syncPublisher(topic);

    this.propertyFields = Arrays.asList(
            new PropertyField(key.pathKey, pathField),
            new PropertyField(key.flagsKey, flagsField));

    GuiUtil.addFolderListener(pathField, command);
    GuiUtil.addApplyPathAction(autoFindButton, pathField, command);
    updateVersion();
}
项目:GitToolBox    文件:IdeaMocksExtension.java   
@Override
public void beforeEach(ExtensionContext context) {
  IdeaMocksImpl ideaMocks = new IdeaMocksImpl();
  Project project = mock(Project.class);
  MessageBus messageBus = mock(MessageBus.class);
  when(project.getMessageBus()).thenReturn(messageBus);
  when(messageBus.syncPublisher(any(Topic.class))).thenAnswer(invocation -> {
    Topic topic = invocation.getArgument(0);
    Class<?> listenerClass = topic.getListenerClass();
    if (ideaMocks.hasMockListener(listenerClass)) {
      return ideaMocks.getMockListener(listenerClass);
    } else {
      return ideaMocks.mockListener(listenerClass);
    }
  });

  Store store = context.getStore(NS);
  store.put(Project.class, project);
  store.put(MessageBus.class, messageBus);
  store.put(IdeaMocks.class, ideaMocks);
}
项目:tools-idea    文件:MessageBusImpl.java   
@Override
@NotNull
@SuppressWarnings({"unchecked"})
public <L> L syncPublisher(@NotNull final Topic<L> topic) {
  checkNotDisposed();
  L publisher = (L)mySyncPublishers.get(topic);
  if (publisher == null) {
    final Class<L> listenerClass = topic.getListenerClass();
    InvocationHandler handler = new InvocationHandler() {
      @Override
      public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        sendMessage(new Message(topic, method, args));
        return NA;
      }
    };
    publisher = (L)Proxy.newProxyInstance(listenerClass.getClassLoader(), new Class[]{listenerClass}, handler);
    publisher = (L)ConcurrencyUtil.cacheOrGet(mySyncPublishers, topic, publisher);
  }
  return publisher;
}
项目:tools-idea    文件:MessageBusImpl.java   
@Override
@NotNull
@SuppressWarnings({"unchecked"})
public <L> L asyncPublisher(@NotNull final Topic<L> topic) {
  checkNotDisposed();
  L publisher = (L)myAsyncPublishers.get(topic);
  if (publisher == null) {
    final Class<L> listenerClass = topic.getListenerClass();
    InvocationHandler handler = new InvocationHandler() {
      @Override
      public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        postMessage(new Message(topic, method, args));
        return NA;
      }
    };
    publisher = (L)Proxy.newProxyInstance(listenerClass.getClassLoader(), new Class[]{listenerClass}, handler);
    publisher = (L)ConcurrencyUtil.cacheOrGet(myAsyncPublishers, topic, publisher);
  }
  return publisher;
}
项目:tools-idea    文件:MessageBusImpl.java   
private void postMessage(Message message) {
  checkNotDisposed();
  final Topic topic = message.getTopic();
  final List<MessageBusConnectionImpl> topicSubscribers = mySubscribers.get(topic);
  if (topicSubscribers != null) {
    Queue<DeliveryJob> queue = myMessageQueue.get();
    for (MessageBusConnectionImpl subscriber : topicSubscribers) {
      queue.offer(new DeliveryJob(subscriber, message));
      subscriber.scheduleMessageDelivery(message);
    }
  }

  Topic.BroadcastDirection direction = topic.getBroadcastDirection();

  if (direction == Topic.BroadcastDirection.TO_CHILDREN) {
    for (MessageBusImpl childBus : myChildBuses) {
      childBus.postMessage(message);
    }
  }

  if (direction == Topic.BroadcastDirection.TO_PARENT && myParentBus != null) {
    myParentBus.postMessage(message);
  }
}
项目:consulo    文件:MessageBusImpl.java   
@Override
@Nonnull
@SuppressWarnings("unchecked")
public <L> L syncPublisher(@Nonnull final Topic<L> topic) {
  checkNotDisposed();
  L publisher = (L)mySyncPublishers.get(topic);
  if (publisher == null) {
    final Class<L> listenerClass = topic.getListenerClass();
    InvocationHandler handler = new InvocationHandler() {
      @Override
      public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        sendMessage(new Message(topic, method, args));
        return NA;
      }
    };
    publisher = (L)Proxy.newProxyInstance(listenerClass.getClassLoader(), new Class[]{listenerClass}, handler);
    publisher = (L)ConcurrencyUtil.cacheOrGet(mySyncPublishers, topic, publisher);
  }
  return publisher;
}
项目:consulo    文件:MessageBusImpl.java   
@Override
@Nonnull
@SuppressWarnings("unchecked")
public <L> L asyncPublisher(@Nonnull final Topic<L> topic) {
  checkNotDisposed();
  L publisher = (L)myAsyncPublishers.get(topic);
  if (publisher == null) {
    final Class<L> listenerClass = topic.getListenerClass();
    InvocationHandler handler = new InvocationHandler() {
      @Override
      public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        postMessage(new Message(topic, method, args));
        return NA;
      }
    };
    publisher = (L)Proxy.newProxyInstance(listenerClass.getClassLoader(), new Class[]{listenerClass}, handler);
    publisher = (L)ConcurrencyUtil.cacheOrGet(myAsyncPublishers, topic, publisher);
  }
  return publisher;
}
项目:consulo    文件:MessageBusImpl.java   
private void calcSubscribers(Topic topic, List<MessageBusConnectionImpl> result) {
  final List<MessageBusConnectionImpl> topicSubscribers = mySubscribers.get(topic);
  if (topicSubscribers != null) {
    result.addAll(topicSubscribers);
  }

  Topic.BroadcastDirection direction = topic.getBroadcastDirection();

  if (direction == Topic.BroadcastDirection.TO_CHILDREN) {
    for (MessageBusImpl childBus : myChildBuses) {
      childBus.calcSubscribers(topic, result);
    }
  }

  if (direction == Topic.BroadcastDirection.TO_PARENT && myParentBus != null) {
    myParentBus.calcSubscribers(topic, result);
  }
}
项目:intellij-ce-playground    文件:MessageBusUtil.java   
public static <T> void runOnSyncPublisher(final Project project, final Topic<T> topic, final Consumer<T> listener) {
  final Application application = ApplicationManager.getApplication();
  final Runnable runnable = createPublisherRunnable(project, topic, listener);
  if (application.isDispatchThread()) {
    runnable.run();
  } else {
    application.runReadAction(runnable);
  }
}
项目:intellij-ce-playground    文件:MessageBusUtil.java   
private static <T> Runnable createPublisherRunnable(final Project project, final Topic<T> topic, final Consumer<T> listener) {
  return new Runnable() {
    @Override
    public void run() {
      if (project.isDisposed()) throw new ProcessCanceledException();
      listener.consume(project.getMessageBus().syncPublisher(topic));
    }
  };
}
项目:intellij-ce-playground    文件:MessageBusUtil.java   
public static <T> void invokeLaterIfNeededOnSyncPublisher(final Project project, final Topic<T> topic, final Consumer<T> listener) {
  final Application application = ApplicationManager.getApplication();
  final Runnable runnable = createPublisherRunnable(project, topic, listener);
  if (application.isDispatchThread()) {
    runnable.run();
  } else {
    application.invokeLater(runnable);
  }
}
项目:intellij-ce-playground    文件:MessageBusConnectionImpl.java   
@Override
public <L> void subscribe(@NotNull Topic<L> topic, @NotNull L handler) throws IllegalStateException {
  synchronized (myPendingMessages) {
    if (mySubscriptions.get(topic) != null) {
      throw new IllegalStateException("Subscription to " + topic + " already exists");
    }
    mySubscriptions = mySubscriptions.plus(topic, handler);
  }
  myBus.notifyOnSubscription(this, topic);
}
项目:intellij-ce-playground    文件:MessageBusConnectionImpl.java   
@Override
@SuppressWarnings("unchecked")
public <L> void subscribe(@NotNull Topic<L> topic) throws IllegalStateException {
  if (myDefaultHandler == null) {
    throw new IllegalStateException("Connection must have default handler installed prior to any anonymous subscriptions. "
                                    + "Target topic: " + topic);
  }
  if (topic.getListenerClass().isInstance(myDefaultHandler)) {
    throw new IllegalStateException("Can't subscribe to the topic '" + topic +"'. Default handler has incompatible type - expected: '" +
                                    topic.getListenerClass() + "', actual: '" + myDefaultHandler.getClass() + "'");
  }

  subscribe(topic, (L)myDefaultHandler);
}
项目:intellij-ce-playground    文件:MessageBusImpl.java   
void notifyOnSubscription(final MessageBusConnectionImpl connection, final Topic topic) {
  checkNotDisposed();
  List<MessageBusConnectionImpl> topicSubscribers = mySubscribers.get(topic);
  if (topicSubscribers == null) {
    topicSubscribers = ContainerUtil.createLockFreeCopyOnWriteList();
    topicSubscribers = ConcurrencyUtil.cacheOrGet(mySubscribers, topic, topicSubscribers);
  }

  topicSubscribers.add(connection);
  getRootBus().clearSubscriberCache();
}
项目:tools-idea    文件:MessageBusUtil.java   
public static <T> void runOnSyncPublisher(final Project project, final Topic<T> topic, final Consumer<T> listener) {
  final Application application = ApplicationManager.getApplication();
  final Runnable runnable = createPublisherRunnable(project, topic, listener);
  if (application.isDispatchThread()) {
    runnable.run();
  } else {
    application.runReadAction(runnable);
  }
}
项目:tools-idea    文件:MessageBusUtil.java   
private static <T> Runnable createPublisherRunnable(final Project project, final Topic<T> topic, final Consumer<T> listener) {
  return new Runnable() {
    @Override
    public void run() {
      if (project.isDisposed()) throw new ProcessCanceledException();
      listener.consume(project.getMessageBus().syncPublisher(topic));
    }
  };
}
项目:tools-idea    文件:MessageBusUtil.java   
public static <T> void invokeLaterIfNeededOnSyncPublisher(final Project project, final Topic<T> topic, final Consumer<T> listener) {
  final Application application = ApplicationManager.getApplication();
  final Runnable runnable = createPublisherRunnable(project, topic, listener);
  if (application.isDispatchThread()) {
    runnable.run();
  } else {
    application.invokeLater(runnable);
  }
}
项目:tools-idea    文件:MessageBusConnectionImpl.java   
@Override
public <L> void subscribe(@NotNull Topic<L> topic, @NotNull L handler) throws IllegalStateException {
  synchronized (myPendingMessages) {
    if (mySubscriptions.get(topic) != null) {
      throw new IllegalStateException("Subscription to " + topic + " already exists");
    }
    mySubscriptions = mySubscriptions.plus(topic, handler);
  }
  myBus.notifyOnSubscription(this, topic);
}
项目:tools-idea    文件:MessageBusConnectionImpl.java   
@Override
@SuppressWarnings("unchecked")
public <L> void subscribe(@NotNull Topic<L> topic) throws IllegalStateException {
  if (myDefaultHandler == null) {
    throw new IllegalStateException("Connection must have default handler installed prior to any anonymous subscriptions. "
                                    + "Target topic: " + topic);
  }
  if (topic.getListenerClass().isInstance(myDefaultHandler)) {
    throw new IllegalStateException("Can't subscribe to the topic '" + topic +"'. Default handler has incompatible type - expected: '" +
      topic.getListenerClass() + "', actual: '" + myDefaultHandler.getClass() + "'");
  }

  subscribe(topic, (L)myDefaultHandler);
}
项目:tools-idea    文件:MessageBusImpl.java   
void notifyOnSubscription(final MessageBusConnectionImpl connection, final Topic topic) {
  checkNotDisposed();
  List<MessageBusConnectionImpl> topicSubscribers = mySubscribers.get(topic);
  if (topicSubscribers == null) {
    topicSubscribers = ContainerUtil.createLockFreeCopyOnWriteList();
    topicSubscribers = ConcurrencyUtil.cacheOrGet(mySubscribers, topic, topicSubscribers);
  }

  topicSubscribers.add(connection);
}
项目:consulo    文件:BackgroundTaskUtil.java   
/**
 * Wraps {@link MessageBus#syncPublisher(Topic)} in a dispose check,
 * and throws a {@link ProcessCanceledException} if the project is disposed,
 * instead of throwing an assertion which would happen otherwise.
 *
 * @see #syncPublisher(Topic)
 */
@Nonnull
public static <L> L syncPublisher(@Nonnull Project project, @Nonnull Topic<L> topic) throws ProcessCanceledException {
  return ReadAction.compute(() -> {
    if (project.isDisposed()) throw new ProcessCanceledException();
    return project.getMessageBus().syncPublisher(topic);
  });
}
项目:consulo    文件:BackgroundTaskUtil.java   
/**
 * Wraps {@link MessageBus#syncPublisher(Topic)} in a dispose check,
 * and throws a {@link ProcessCanceledException} if the application is disposed,
 * instead of throwing an assertion which would happen otherwise.
 *
 * @see #syncPublisher(Project, Topic)
 */
@Nonnull
public static <L> L syncPublisher(@Nonnull Topic<L> topic) throws ProcessCanceledException {
  return ReadAction.compute(() -> {
    if (ApplicationManager.getApplication().isDisposed()) throw new ProcessCanceledException();
    return ApplicationManager.getApplication().getMessageBus().syncPublisher(topic);
  });
}
项目:consulo    文件:MessageBusUtil.java   
public static <T> void runOnSyncPublisher(final Project project, final Topic<T> topic, final Consumer<T> listener) {
  final Application application = ApplicationManager.getApplication();
  final Runnable runnable = createPublisherRunnable(project, topic, listener);
  if (application.isDispatchThread()) {
    runnable.run();
  } else {
    application.runReadAction(runnable);
  }
}
项目:consulo    文件:MessageBusUtil.java   
private static <T> Runnable createPublisherRunnable(final Project project, final Topic<T> topic, final Consumer<T> listener) {
  return new Runnable() {
    @Override
    public void run() {
      if (project.isDisposed()) throw new ProcessCanceledException();
      listener.consume(project.getMessageBus().syncPublisher(topic));
    }
  };
}
项目:consulo    文件:MessageBusUtil.java   
public static <T> void invokeLaterIfNeededOnSyncPublisher(final Project project, final Topic<T> topic, final Consumer<T> listener) {
  final Application application = ApplicationManager.getApplication();
  final Runnable runnable = createPublisherRunnable(project, topic, listener);
  if (application.isDispatchThread()) {
    runnable.run();
  } else {
    application.invokeLater(runnable);
  }
}
项目:consulo    文件:MessageBusConnectionImpl.java   
@Override
public <L> void subscribe(@Nonnull Topic<L> topic, @Nonnull L handler) throws IllegalStateException {
  synchronized (myPendingMessages) {
    if (mySubscriptions.get(topic) != null) {
      throw new IllegalStateException("Subscription to " + topic + " already exists");
    }
    mySubscriptions = mySubscriptions.plus(topic, handler);
  }
  myBus.notifyOnSubscription(this, topic);
}
项目:consulo    文件:MessageBusConnectionImpl.java   
@Override
public <L> void subscribe(@Nonnull Topic<L> topic) throws IllegalStateException {
  if (myDefaultHandler == null) {
    throw new IllegalStateException("Connection must have default handler installed prior to any anonymous subscriptions. "
                                    + "Target topic: " + topic);
  }
  if (topic.getListenerClass().isInstance(myDefaultHandler)) {
    throw new IllegalStateException("Can't subscribe to the topic '" + topic +"'. Default handler has incompatible type - expected: '" +
                                    topic.getListenerClass() + "', actual: '" + myDefaultHandler.getClass() + "'");
  }

  //noinspection unchecked
  subscribe(topic, (L)myDefaultHandler);
}
项目:consulo    文件:MessageBusConnectionImpl.java   
boolean containsMessage(@Nonnull Topic topic) {
  for (Message message : myPendingMessages.get()) {
    if (message.getTopic() == topic) {
      return true;
    }
  }
  return false;
}
项目:consulo    文件:MessageBusImpl.java   
@Override
public boolean hasUndeliveredEvents(@Nonnull Topic<?> topic) {
  if (!isDispatchingAnything()) return false;

  for (MessageBusConnectionImpl connection : getTopicSubscribers(topic)) {
    if (connection.containsMessage(topic)) {
      return true;
    }
  }
  return false;
}
项目:consulo    文件:MessageBusImpl.java   
@Nonnull
private List<MessageBusConnectionImpl> getTopicSubscribers(Topic topic) {
  List<MessageBusConnectionImpl> topicSubscribers = mySubscriberCache.get(topic);
  if (topicSubscribers == null) {
    topicSubscribers = new SmartList<MessageBusConnectionImpl>();
    calcSubscribers(topic, topicSubscribers);
    mySubscriberCache.put(topic, topicSubscribers);
  }
  return topicSubscribers;
}
项目:consulo    文件:MessageBusImpl.java   
void notifyOnSubscription(@Nonnull MessageBusConnectionImpl connection, @Nonnull Topic<?> topic) {
  checkNotDisposed();
  List<MessageBusConnectionImpl> topicSubscribers = mySubscribers.get(topic);
  if (topicSubscribers == null) {
    topicSubscribers = ContainerUtil.createLockFreeCopyOnWriteList();
    topicSubscribers = ConcurrencyUtil.cacheOrGet(mySubscribers, topic, topicSubscribers);
  }

  topicSubscribers.add(connection);
  rootBus().clearSubscriberCache();
}
项目:intellij-ce-playground    文件:AbstractExternalSystemSettings.java   
protected AbstractExternalSystemSettings(@NotNull Topic<L> topic, @NotNull Project project) {
  myChangesTopic = topic;
  myProject = project;
  Disposer.register(project, this);
}
项目:intellij-ce-playground    文件:AbstractExternalSystemSettings.java   
@NotNull
public Topic<L> getChangesTopic() {
  return myChangesTopic;
}
项目:intellij-ce-playground    文件:Message.java   
public Message(@NotNull Topic topic, @NotNull Method listenerMethod, Object[] args) {
  myTopic = topic;
  listenerMethod.setAccessible(true);
  myListenerMethod = listenerMethod;
  myArgs = args;
}
项目:intellij-ce-playground    文件:Message.java   
@NotNull
public Topic getTopic() {
  return myTopic;
}
项目:intellij-ce-playground    文件:MessageListenerList.java   
public MessageListenerList(@NotNull MessageBus messageBus, @NotNull Topic<T> topic) {
  myTopic = topic;
  myMessageBus = messageBus;
}