/** * Creates the and start. * * @param main the main * @param workers the workers */ public static void createAndStart( Class<? extends ComponentDefinition> main, int workers) { createAndStart(main, Init.NONE, workers, 1); }
@Override public void run() { Kompics.shutdown();; } };
protected void escalateFaultToKompics(Fault fault) { Kompics.handleFault(fault); }
public static synchronized void runAtLeastTests(NetworkGenerator nGen, int numNodes, Transport[] protos) { LOG.info("\n******************** Running AT LEAST Test ********************\n"); NetworkTest.nGen = nGen; NetworkTest.numNodes = numNodes; NetworkTest.protos = protos; WAIT_FOR.set(1); msgId.set(0); messageStatus.clear(); TestUtil.reset("Datagram test (" + Arrays.toString(NetworkTest.protos) + ") Nodes #" + numNodes, 10000); //10 sec timeout for all the connections to be dropped properly Kompics.createAndStart(LauncherComponent.class, 8, 50); for (int i = 0; i < numNodes; i++) { LOG.info("Waiting for {}/{} STOPPED.", i + 1, numNodes); TestUtil.waitFor(STOPPED); LOG.info("Got {}/{} STOPPED.", i + 1, numNodes); } LOG.info("\n******************** Shutting Down Kompics ********************\n"); Kompics.shutdown(); assertTrue(numNodes <= messageStatus.size()); LOG.info("\n******************** AT LEAST Test Done ********************\n"); }
@Override public void run() { ResolveAction ra = fh.handle(f); switch (ra) { case RESOLVED: Kompics.logger.info("Fault {} was resolved by user.", f); break; case IGNORE: Kompics.logger.info("Fault {} was declared to be ignored by user. Resuming component...", f); f.source.markSubtreeAs(Component.State.PASSIVE); f.source.control().doTrigger(Start.event, 0, mainCore); break; case DESTROY: Kompics.logger.info("User declared that Fault {} should quit Kompics...", f); Kompics.forceShutdown(); { try { Kompics.waitForTermination(); } catch (InterruptedException ex) { Kompics.logger.error("Interrupted while waiting for Kompics termination..."); System.exit(1); } } Kompics.logger.info("finished quitting Kompics."); break; default: Kompics.logger.info("User declared that Fault {} should quit JVM...", f); System.exit(1); } }
@Override public void uncaughtException(Thread t, Throwable e) { Kompics.getFaultHandler().handle(new Fault(e, null, null)); }
@Override public void handle(Data event) { if (first) { startTS = System.currentTimeMillis(); first = false; } System.arraycopy(event.data, 0, data, event.pos, DataMessage.MESSAGE_SIZE); tracker.add(event.pos); System.out.println("Received message #"+event.pos); if (tracker.size() == event.total) { long endTS = System.currentTimeMillis(); double diff = ((double) endTS - startTS)/1000.0; double throughput = ((double)data.length)/(diff*1024.0); System.out.println("Transfer complete! Data received in " + diff + "s with " + throughput + "kb/s"); Kompics.asyncShutdown(); } } };
protected void schedule(int wid) { if (scheduler == null) { scheduler = Kompics.getScheduler(); } scheduler.schedule(this, wid); }
/** * Instantiates a new component core. * <p> * @param componentDefinition the component definition */ public JavaComponent(ComponentDefinition componentDefinition) { this.positivePorts = new HashMap<Class<? extends PortType>, JavaPort<? extends PortType>>(); this.negativePorts = new HashMap<Class<? extends PortType>, JavaPort<? extends PortType>>(); this.parent = parentThreadLocal.get(); if (this.parent != null) { this.conf = parent.conf.copy(componentDefinition.separateConfigId()); } else { this.conf = Kompics.getConfig().copy(componentDefinition.separateConfigId()); } if (childUpdate.get().isPresent()) { Config.Impl ci = (Config.Impl) this.conf; ci.apply(childUpdate.get().get(), ValueMerger.NONE); Optional<ConfigUpdate> resetUpdate = Optional.absent(); childUpdate.set(resetUpdate); } this.component = componentDefinition; parentThreadLocal.set(null); executeNEvents = Kompics.maxNumOfExecutedEvents.get(); }
TestUtil.reset("Stream test (" + Arrays.toString(NetworkTest.protos) + ") Nodes #" + numNodes, 100000); //10 sec timeout for all the connections to be dropped properly Kompics.createAndStart(LauncherComponent.class, 8, 50); Kompics.shutdown(); Kompics.createAndStart(FRLauncher.class, 8, 50); Kompics.shutdown(); assertEquals(NUM_FR_MESSAGES, messageStatus.size()); for (String s : messageStatus.values()) { TestUtil.reset("FR test (" + Arrays.toString(NetworkTest.protos) + ")", 100000); //10 sec timeout for all the connections to be dropped properly Kompics.createAndStart(FRLauncher.class, 8, 50); Kompics.shutdown(); assertEquals(NUM_FR_MESSAGES, messageStatus.size()); for (String s : messageStatus.values()) {
@Override protected boolean exec() { try { run(); return false; // } catch(InterruptedException ex) { // Thread.currentThread().interrupt(); // return false; // } } catch (Throwable e) { Kompics.getFaultHandler().handle(new Fault(e, this, null)); throw e; } } }
double throughput = ((double) (DATA_VOLUME * DataMessage.MESSAGE_SIZE)) / (diff * 1024.0); System.out.println("Transfer complete! Data sent in " + diff + "s with " + throughput + "kb/s"); Kompics.asyncShutdown();
public static void createAndStart(Class<? extends ComponentDefinition> main, Init initEvent) { createAndStart(main, initEvent, 1); }
@Override public void escalateFault(Fault fault) { if (parent != null) { parent.control().doTrigger(fault, wid, this); } else { // StackTraceElement[] stackTrace = throwable.getStackTrace(); // System.err.println("Kompics isolated fault: " // + throwable.getMessage()); // do { // for (int i = 0; i < stackTrace.length; i++) { // System.err.println(" " + stackTrace[i]); // } // throwable = throwable.getCause(); // if (throwable != null) { // stackTrace = throwable.getStackTrace(); // System.err.println("Caused by: " + throwable + ": " // + throwable.getMessage()); // } // } while (throwable != null); logger().error("A fault was escalated to the root component: \n{} \n\n", fault); Kompics.handleFault(fault); // System.exit(1); } }
/** * Creates the and start. * * @param main the main */ public static void createAndStart(Class<? extends ComponentDefinition> main) { // createAndStart(main, Runtime.getRuntime().availableProcessors()); createAndStart(main, Init.NONE, 1); }
public static void createAndStart( Class<? extends ComponentDefinition> main, Init initEvent, int workers) { createAndStart(main, initEvent, workers, 1); }
public static void createAndStart( Class<? extends ComponentDefinition> main, int workers, int maxEventExecuteNumber) { createAndStart(main, Init.NONE, workers, maxEventExecuteNumber); }
public static void main(String[] args) throws UnknownHostException { InetAddress ip = InetAddress.getByName(args[0]); int port = Integer.parseInt(args[1]); Address selfAddress = new NettyAddress(ip, port); Kompics.createAndStart(Parent.class, new Parent.Init(selfAddress), 2, 50); }
public static void main(String[] args) throws UnknownHostException { InetAddress ip = InetAddress.getByName(args[0]); int port = Integer.parseInt(args[1]); Address selfAddress = new NettyAddress(ip, port); InetAddress ip2 = InetAddress.getByName(args[2]); int port2 = Integer.parseInt(args[3]); Address targetAddress = new NettyAddress(ip2, port2); Kompics.createAndStart(Parent.class, new Parent.Init(selfAddress, targetAddress), Receiver.THREADS, 50); }