Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright (c) 2007-2014 Sonatype, Inc. All rights reserved.
  *
  * This program is licensed to you under the Apache License Version 2.0,
  * and you may not use this file except in compliance with the Apache License Version 2.0.
  * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
  *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the Apache License Version 2.0 is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
 */
package com.google.common.eventbus;
A Guava com.google.common.eventbus.EventBus that differs from default one by dispatching events as they appear (is re-entrant). Guava will queue up all event and dispatch them in the order they were posted, without re-entrance.

Since:
1.5
@Named("reentrant")
    extends DefaultGuavaEventBus
{

  
Queues of events for the current thread to dispatch.
      {
        @Override
        protected Queue<EventWithSubscriberinitialValue() {
          return new LinkedList<EventWithSubscriber>();
        }
      };
  void enqueueEvent(Object eventEventSubscriber subscriber) {
    .get().offer(new EventWithSubscriber(eventsubscriber));
  }
  void dispatchQueuedEvents() {
    EventWithSubscriber eventWithSubscriber;
    while ((eventWithSubscriber = events.poll()) != null) {
      dispatch(eventWithSubscriber.eventeventWithSubscriber.subscriber);
    }
  }
  public String toString() {
    return "Reentrant Guava EventBus";
  }
New to GrepCode? Check out our FAQ X