Mercurial > hg > FederatedLinda
view src/fdl/test/api/inout/InOutMetaEngine.java @ 111:29ed7feebf2a
add API test for in()out() and update().
author | kazz |
---|---|
date | Fri, 20 Aug 2010 21:22:51 +0900 |
parents | |
children | 27874f473d48 |
line wrap: on
line source
package fdl.test.api.inout; import java.io.IOException; import java.nio.ByteBuffer; import java.util.Date; import fdl.MetaEngine; import fdl.MetaLinda; import fdl.PSXLinda; import fdl.PSXReply; public class InOutMetaEngine implements MetaEngine { private final static int targetId = 1000; private String host; private int port; private int maxCount, count = 0; private MetaLinda ml; private PSXLinda linda; private PSXReply reply; private Date startTime, endTime; private InOutMetaEngine(MetaLinda metaLinda, String host, int port, int count) { this.ml = metaLinda; this.host = host; this.port = port; this.maxCount = count; } private void connect() { try { linda = ml.open(host, port); } catch (IOException e) { e.printStackTrace(); } } public void mainLoop(MetaLinda ml) { if (count >= maxCount) { endTime = new Date(); Long resultTime = new Long(endTime.getTime() - startTime.getTime()); System.out.println(resultTime); System.exit(0); } if (reply == null) { reply = linda.in(targetId); linda.out(targetId, ByteBuffer.wrap("test".getBytes())); return; } if (reply.ready()) { reply = null; count++; } } public static InOutMetaEngine create(MetaLinda metaLinda, String host, int port, int count) { InOutMetaEngine iome = new InOutMetaEngine(metaLinda, host, port, count); iome.connect(); iome.linda.out(targetId, ByteBuffer.wrap("test".getBytes())); try { iome.linda.sync(); } catch (IOException e) { e.printStackTrace(); } iome.startTime = new Date(); return iome; } }