// Path: core/src/java/com/strategicgains/eventing/EventHandler.java
// public interface EventHandler
// {
// 	/**
// 	 * Process the given event. Called by the EventMonitor when an event occurs.
// 	 * 
// 	 * @param event
// 	 * @throws Exception if something goes wrong
// 	 */
// 	public void handle(Object event)
// 	throws Exception;
// 	
// 	/**
// 	 * Answers whether this EventHandler can handle events of the given type.
// 	 * If true is returned, the EventMonitor will call handle(), otherwise,
// 	 * the EventMonitor will not ask this event handler to process the event.
// 	 * 
// 	 * @param eventClass
// 	 * @return
// 	 */
// 	public boolean handles(Class<?> eventClass);
// }
// 
// Path: core/src/java/com/strategicgains/eventing/EventTransport.java
// public interface EventTransport
// {
// 	public void publish(Object event);
//     public boolean subscribe(EventHandler handler);
//     public boolean unsubscribe(EventHandler handler);
// 	public void shutdown();
// }


import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.event.japi.ScanningEventBus;
import com.strategicgains.eventing.EventHandler;
import com.strategicgains.eventing.EventTransport;
/*
    Copyright 2015, Strategic Gains, Inc.

	Licensed under the Apache License, Version 2.0 (the "License");
	you may not use this file except in compliance with the License.
	You may obtain a copy of the License at

		http://www.apache.org/licenses/LICENSE-2.0

	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
*/
package com.strategicgains.eventing.akka;




/**
 * @author toddf
 * @since Jul 13, 2015
 */
public class AkkaEventTransport
implements EventTransport
{
	private ActorSystem system;
	private Map<EventHandler, ActorRef> subscribers = new ConcurrentHashMap<EventHandler, ActorRef>();
	private AkkaBusImpl akkaBus;

	public AkkaEventTransport(ActorSystem actorSystem)
    {
		super();
		this.system = actorSystem;
		akkaBus = new AkkaBusImpl();
    }

	@Override
	public void publish(Object event)
	{
		akkaBus.publish(event);
	}

	@Override
	public boolean subscribe(EventHandler handler)
	{
		ActorRef adapter = system.actorOf(EventHandlerActor.props(handler));
		akkaBus.subscribe(adapter, Object.class);
		subscribers.put(handler, adapter);
		return true;
	}

	@Override
// Path: core/src/java/com/strategicgains/eventing/EventHandler.java
// public interface EventHandler
// {
// 	/**
// 	 * Process the given event. Called by the EventMonitor when an event occurs.
// 	 * 
// 	 * @param event
// 	 * @throws Exception if something goes wrong
// 	 */
// 	public void handle(Object event)
// 	throws Exception;
// 	
// 	/**
// 	 * Answers whether this EventHandler can handle events of the given type.
// 	 * If true is returned, the EventMonitor will call handle(), otherwise,
// 	 * the EventMonitor will not ask this event handler to process the event.
// 	 * 
// 	 * @param eventClass
// 	 * @return
// 	 */
// 	public boolean handles(Class<?> eventClass);
// }
// 
// Path: core/src/java/com/strategicgains/eventing/EventTransport.java
// public interface EventTransport
// {
// 	public void publish(Object event);
//     public boolean subscribe(EventHandler handler);
//     public boolean unsubscribe(EventHandler handler);
// 	public void shutdown();
// }


// Path: akka/src/main/java/com/strategicgains/eventing/akka/AkkaEventTransport.java
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.event.japi.ScanningEventBus;
import com.strategicgains.eventing.EventHandler;
import com.strategicgains.eventing.EventTransport;

/*
    Copyright 2015, Strategic Gains, Inc.

	Licensed under the Apache License, Version 2.0 (the "License");
	you may not use this file except in compliance with the License.
	You may obtain a copy of the License at

		http://www.apache.org/licenses/LICENSE-2.0

	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
*/
package com.strategicgains.eventing.akka;




/**
 * @author toddf
 * @since Jul 13, 2015
 */
public class AkkaEventTransport
implements EventTransport
{
	private ActorSystem system;
	private Map<EventHandler, ActorRef> subscribers = new ConcurrentHashMap<EventHandler, ActorRef>();
	private AkkaBusImpl akkaBus;

	public AkkaEventTransport(ActorSystem actorSystem)
    {
		super();
		this.system = actorSystem;
		akkaBus = new AkkaBusImpl();
    }

	@Override
	public void publish(Object event)
	{
		akkaBus.publish(event);
	}

	@Override
	public boolean subscribe(EventHandler handler)
	{
		ActorRef adapter = system.actorOf(EventHandlerActor.props(handler));
		akkaBus.subscribe(adapter, Object.class);
		subscribers.put(handler, adapter);
		return true;
	}

	@Override
	public boolean unsubscribe(EventHandler handler)