view src/fdl/MetaLogEngine.java @ 122:ad73eacf560a default tip

remove warning
author e095732
date Thu, 07 Feb 2013 22:32:26 +0900
parents 0ea086f0e96f
children
line wrap: on
line source

package fdl;

import java.nio.ByteBuffer;

/**
 * @author kono
 *    Meta Protocol Engine for each Linda Server
 */

public class MetaLogEngine implements MetaEngine {
	MetaLinda meta;
	boolean running = true;
	CommDebugHook commDebug;

	public MetaLogEngine(MetaLinda meta) {
		this.meta = meta;
	}
	
	PSXCallback monitor_callback_start =
			new PSXCallback() {public void callback(ByteBuffer reply) { 
				meta.setTupleSpaceHook(commDebug = new CommDebugHook());
				meta.out(PSX.META_MONITOR_DATA, null);
				meta.in(PSX.META_MONITOR,monitor_callback);
	}};
	PSXCallback monitor_callback =
		new PSXCallback() {public void callback(ByteBuffer reply) {
			ByteBuffer data;
			do {
				data = commDebug.getLog();
				if (data!=null) break;
				meta.sync(0);
			} while (running);
			if (running) {
				meta.out(PSX.META_MONITOR_DATA, data);
				meta.in(PSX.META_MONITOR,monitor_callback);
			}
		}};
	
	public void mainLoop(MetaLinda meta) {
		meta.in(PSX.META_MONITOR,monitor_callback_start);
		meta.in(PSX.META_STOP, new PSXCallback() {public void callback(ByteBuffer reply) {
			running = false;}});
		while(running) 
			meta.sync(0);
	}
}