// Path: koper-reactor/src/main/java/koper/reactor/ReactorRef.java
// public class ReactorRef {
// 	
// 	private long id;
// 	private Class<? extends Reactor> reactorClass;
// 	public MessageSender messageSender;
// 
// 	private static final Random rd = new Random();
// 	/**
// 	 * 
// 	 */
// 	private ReactorRef(Class<? extends Reactor> reactorClass) {
// 		this.reactorClass = reactorClass;
// 	}
// 	
// 	/**
// 	 * @param id the id to set
// 	 */
// 	public void setId(long id) {
// 		this.id = id;
// 	}
// 	
// 	/**
// 	 * @return the id
// 	 */
// 	public long getId() {
// 		return id;
// 	}
// 	
// 	/**
// 	 * Create a remote object. Specify a random global id;
// 	 * @param reactorClass
// 	 * @return
// 	 */
// 	public static ReactorRef create(Class<? extends Reactor> reactorClass) {
// 		ReactorRef ref = new ReactorRef(reactorClass);
// 		long id = rd.nextLong();
// 		id = id<0 ? -id : id;
// 		ref.setId(id);
// 		return  ref;
// 	}
// 	
// 	/**
// 	 * Refer to an existing remote object with a given id.
// 	 * @param id
// 	 * @param reactorClass
// 	 * @return
// 	 */
// 	public static ReactorRef ref( Class<? extends Reactor> reactorClass,long id) {
// 		ReactorRef ref = new ReactorRef(reactorClass);
// 		ref.setId(id);
// 		return ref;
// 	}
// 	
// 	public void setMessageSender(MessageSender messageSender) {
// 		this.messageSender = messageSender;
// 	}
// 	
// 	/**
// 	 * send message to remote object refered by this ref
// 	 * @param message
// 	 */
// 	public void send(Object message) {
// 		String className = reactorClass.getName();
// 		String classAndMethod = className ;
// 		System.out.println("id " + id);
// 		messageSender.send(classAndMethod , String.valueOf( id ) , message);
// 	}
// 	
// 	public static void main(String[] args) {
// 		Random rd = new Random(1000);
// 		for(int i=0;i<10;i++) {
// 			long id = rd.nextLong();
// 			id = id<0? -id : id;
// 			System.out.println("x " + id);
// 		}
// 	}
// }
// 
// Path: koper-core/src/main/java/koper/sender/MessageSender.java
// public interface MessageSender {
// 
//     void send(String topic, String msg);
// 
//     void send(String topic, String key, String msg);
// 
//     void send(String topic, Object msg);
// 
//     void send(String topic, String key, Object msg);
// }


import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import koper.reactor.ReactorRef;
import koper.sender.MessageSender;
import scala.util.Random;
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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 koper.reactor.demo;



/**
 * ProducerApp
 * @author Raymond He, raymondhekk9527@gmail.com
 * @since 1.0
 * 2016年8月25日
 *
 */
public class ProducerApp {
	
	/**
	 * Reactor produce demo.
	 * Create prototype(multiple instances) reactor and send message to them.
	 * @param args
	 */
	public static void main(String[] args) {
		
		ApplicationContext context = new ClassPathXmlApplicationContext("classpath:kafka/context-data-producer.xml");
// Path: koper-reactor/src/main/java/koper/reactor/ReactorRef.java
// public class ReactorRef {
// 	
// 	private long id;
// 	private Class<? extends Reactor> reactorClass;
// 	public MessageSender messageSender;
// 
// 	private static final Random rd = new Random();
// 	/**
// 	 * 
// 	 */
// 	private ReactorRef(Class<? extends Reactor> reactorClass) {
// 		this.reactorClass = reactorClass;
// 	}
// 	
// 	/**
// 	 * @param id the id to set
// 	 */
// 	public void setId(long id) {
// 		this.id = id;
// 	}
// 	
// 	/**
// 	 * @return the id
// 	 */
// 	public long getId() {
// 		return id;
// 	}
// 	
// 	/**
// 	 * Create a remote object. Specify a random global id;
// 	 * @param reactorClass
// 	 * @return
// 	 */
// 	public static ReactorRef create(Class<? extends Reactor> reactorClass) {
// 		ReactorRef ref = new ReactorRef(reactorClass);
// 		long id = rd.nextLong();
// 		id = id<0 ? -id : id;
// 		ref.setId(id);
// 		return  ref;
// 	}
// 	
// 	/**
// 	 * Refer to an existing remote object with a given id.
// 	 * @param id
// 	 * @param reactorClass
// 	 * @return
// 	 */
// 	public static ReactorRef ref( Class<? extends Reactor> reactorClass,long id) {
// 		ReactorRef ref = new ReactorRef(reactorClass);
// 		ref.setId(id);
// 		return ref;
// 	}
// 	
// 	public void setMessageSender(MessageSender messageSender) {
// 		this.messageSender = messageSender;
// 	}
// 	
// 	/**
// 	 * send message to remote object refered by this ref
// 	 * @param message
// 	 */
// 	public void send(Object message) {
// 		String className = reactorClass.getName();
// 		String classAndMethod = className ;
// 		System.out.println("id " + id);
// 		messageSender.send(classAndMethod , String.valueOf( id ) , message);
// 	}
// 	
// 	public static void main(String[] args) {
// 		Random rd = new Random(1000);
// 		for(int i=0;i<10;i++) {
// 			long id = rd.nextLong();
// 			id = id<0? -id : id;
// 			System.out.println("x " + id);
// 		}
// 	}
// }
// 
// Path: koper-core/src/main/java/koper/sender/MessageSender.java
// public interface MessageSender {
// 
//     void send(String topic, String msg);
// 
//     void send(String topic, String key, String msg);
// 
//     void send(String topic, Object msg);
// 
//     void send(String topic, String key, Object msg);
// }


// Path: koper-reactor/src/test/java/koper/reactor/demo/ProducerApp.java
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import koper.reactor.ReactorRef;
import koper.sender.MessageSender;
import scala.util.Random;

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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 koper.reactor.demo;



/**
 * ProducerApp
 * @author Raymond He, raymondhekk9527@gmail.com
 * @since 1.0
 * 2016年8月25日
 *
 */
public class ProducerApp {
	
	/**
	 * Reactor produce demo.
	 * Create prototype(multiple instances) reactor and send message to them.
	 * @param args
	 */
	public static void main(String[] args) {
		
		ApplicationContext context = new ClassPathXmlApplicationContext("classpath:kafka/context-data-producer.xml");
		MessageSender messageSender = (MessageSender) context.getBean("messageSender");