The yarn event-driven model of Hadoop

Source: Internet
Author: User

Yran programming has many areas where the event-driven model is used, simplifying the code and making it easier to understand.


1. Define an event:

Import org.apache.hadoop.yarn.event.AbstractEvent;

public class Taskevent extends abstractevent<taskeventtype> {
	
	private String TaskID;
	
	Public Taskevent (String TaskID, Taskeventtype type) {
		super (type);
		This.taskid=taskid;
	}

	Public String GetTaskID () {
		return taskID;
	}

}


2. There are 2 types of this event:

public enum Taskeventtype {
	t_kill,
	t_schedule
}


3. Define a scheduler, and the test code is also written in:

Import org.apache.hadoop.conf.Configuration;
Import Org.apache.hadoop.service.CompositeService;
Import Org.apache.hadoop.service.Service;
Import org.apache.hadoop.yarn.conf.YarnConfiguration;
Import Org.apache.hadoop.yarn.event.AsyncDispatcher;
Import Org.apache.hadoop.yarn.event.Dispatcher;
										
Import Org.apache.hadoop.yarn.event.EventHandler;

	public class Simplemrappmaster extends Compositeservice {//Single Event Service can inherit Abstractservice, how to use it.
	
	Private Dispatcher Dispatcher;
	Public Dispatcher Getdispatcher () {return Dispatcher;
	} public Simplemrappmaster (String name) {super (name);
		} @Override protected void Serviceinit (Configuration arg0) throws Exception {dispatcher = new asyncdispatcher ();
		Dispatcher.register (Taskeventtype.class, New Taskeventdisptacher ());
		AddService (Service) dispatcher);
	Super.serviceinit (arg0); } Private class Taskeventdisptacher implements eventhandler<taskevent>{@Override public void handle (Taskeve NT arg0) {if (arg0.getType () = = Taskeventtype.t_kill) {System.out.println ("Run KILL");
			}else if (arg0.gettype () = = Taskeventtype.t_schedule) {System.out.println ("Run SCHEDULE"); }}}//test portal public static void main (string[] args) throws Exception {Simplemrappmaster master = new Simpl
		Emrappmaster ("Simplemrappmaster");
		Yarnconfiguration conf = new yarnconfiguration ();
		Master.serviceinit (conf);
Master.servicestart ();//Must be a subclass to be called, so the Main method writes to this class, and the main method writes to other classes, which need to be reflected.  Master.init (conf);     These 2 groups of methods test the effect looks the same,//Master.start ();
		Have time to see the API explained Master.getdispatcher (). Geteventhandler (). Handle (New Taskevent ("Task1", Taskeventtype.t_schedule));
	Master.getdispatcher (). Geteventhandler (). Handle (New Taskevent ("Task1", Taskeventtype.t_kill)); }
}

There are some problems, do not understand, first make a record it.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.