@Test public void testSubmitToKeyOwnerCallable() throws Exception { final int k = simpleTestNodeCount; TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(k); final HazelcastInstance[] instances = factory.newInstances(new Config()); final AtomicInteger count = new AtomicInteger(0); final CountDownLatch latch = new CountDownLatch(k / 2); final ExecutionCallback callback = new ExecutionCallback() { public void onResponse(Object response) { if ((Boolean) response) count.incrementAndGet(); latch.countDown(); } public void onFailure(Throwable t) {} }; for (int i = 0; i < k; i++) { final HazelcastInstance instance = instances[i]; final IExecutorService service = instance.getExecutorService("testSubmitToKeyOwnerCallable"); final String script = "hazelcast.getCluster().getLocalMember().equals(member)"; final HashMap map = new HashMap(); final Member localMember = instance.getCluster().getLocalMember(); map.put("member", localMember); int key = 0; while (!localMember.equals(instance.getPartitionService().getPartition(++key).getOwner())) ; if (i % 2 == 0) { final Future f = service.submitToKeyOwner(new ScriptCallable(script, map), key); assertTrue((Boolean) f.get(5, TimeUnit.SECONDS)); } else { service.submitToKeyOwner(new ScriptCallable(script, map), key, callback); } } assertTrue(latch.await(30, TimeUnit.SECONDS)); assertEquals(k / 2, count.get()); }
@Test public void testSubmitToMemberRunnable() throws InterruptedException { final int k = simpleTestNodeCount; TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(k); final HazelcastInstance[] instances = factory.newInstances(new Config()); final AtomicInteger count = new AtomicInteger(0); final CountDownLatch latch = new CountDownLatch(k); final ExecutionCallback callback = new ExecutionCallback() { public void onResponse(Object response) { if (response == null) { count.incrementAndGet(); } latch.countDown(); } public void onFailure(Throwable t) {} }; for (int i = 0; i < k; i++) { final HazelcastInstance instance = instances[i]; final IExecutorService service = instance.getExecutorService("testSubmitToMemberRunnable"); final String script = "if(!hazelcast.getCluster().getLocalMember().equals(member)) " + "hazelcast.getAtomicLong('testSubmitToMemberRunnable').incrementAndGet();"; final HashMap map = new HashMap(); map.put("member", instance.getCluster().getLocalMember()); service.submitToMember( new ScriptRunnable(script, map), instance.getCluster().getLocalMember(), callback); } latch.await(10, TimeUnit.SECONDS); assertEquals(0, instances[0].getAtomicLong("testSubmitToMemberRunnable").get()); assertEquals(k, count.get()); }
@Override protected void setUp() throws Exception { tmp = IO.getFile("generated/tmp"); tmp.mkdirs(); IO.copy(IO.getFile("testdata/ws"), tmp); workspace = Workspace.getWorkspace(tmp); workspace.refresh(); InfoRepository repo = workspace.getPlugin(InfoRepository.class); t1 = create("bsn-1", new Version(1, 0, 0)); t2 = create("bsn-2", new Version(1, 0, 0)); repo.put(new FileInputStream(t1), null); repo.put(new FileInputStream(t2), null); t1 = repo.get("bsn-1", new Version(1, 0, 0), null); t2 = repo.get("bsn-2", new Version(1, 0, 0), null); repo.put(new FileInputStream(IO.getFile("generated/biz.aQute.remote.launcher.jar")), null); workspace.getPlugins().add(repo); File storage = IO.getFile("generated/storage-1"); storage.mkdirs(); configuration = new HashMap<String, Object>(); configuration.put( Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT); configuration.put(Constants.FRAMEWORK_STORAGE, storage.getAbsolutePath()); configuration.put( Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "org.osgi.framework.launch;version=1.2"); framework = new org.apache.felix.framework.FrameworkFactory().newFramework(configuration); framework.init(); framework.start(); context = framework.getBundleContext(); location = "reference:" + IO.getFile("generated/biz.aQute.remote.agent.jar").toURI().toString(); agent = context.installBundle(location); agent.start(); thread = new Thread() { @Override public void run() { try { Main.main( new String[] { "-s", "generated/storage", "-c", "generated/cache", "-p", "1090", "-et" }); } catch (Exception e) { e.printStackTrace(); } } }; thread.setDaemon(true); thread.start(); super.setUp(); }
private void update(ColumnDefinition definition) { AtomicBoolean present = predefined.get(definition); if (present != null) { if (!present.get()) present.set(true); } else { extra.add(definition); } }
/** * Create a property mapping based on the initial values in the deployment descriptor. * * @param dd * @return */ public static Map<QName, Node> calcInitialProperties( Properties properties, TDeployment.Process dd) { HashMap<QName, Node> ret = new HashMap<QName, Node>(); for (Object key1 : properties.keySet()) { String key = (String) key1; Document doc = DOMUtils.newDocument(); doc.appendChild(doc.createElementNS(null, "temporary-simple-type-wrapper")); doc.getDocumentElement().appendChild(doc.createTextNode(properties.getProperty(key))); ret.put(new QName(key), doc.getDocumentElement()); } for (TDeployment.Process.Property property : dd.getPropertyArray()) { Element elmtContent = DOMUtils.getElementContent(property.getDomNode()); if (elmtContent != null) { // We'll need DOM Level 3 Document doc = DOMUtils.newDocument(); doc.appendChild(doc.importNode(elmtContent, true)); ret.put(property.getName(), doc.getDocumentElement()); } else ret.put(property.getName(), property.getDomNode().getFirstChild()); } return ret; }
public PartitionColumns get() { PartitionColumns.Builder builder = PartitionColumns.builder(); for (Map.Entry<ColumnDefinition, AtomicBoolean> e : predefined.entrySet()) if (e.getValue().get()) builder.add(e.getKey()); return builder.addAll(extra).build(); }
ColumnsCollector(PartitionColumns columns) { for (ColumnDefinition def : columns.statics) predefined.put(def, new AtomicBoolean()); for (ColumnDefinition def : columns.regulars) predefined.put(def, new AtomicBoolean()); }
@Override public void onChange(String resource) { try { LOG.debug("Reading " + resource); HashMap<CommandExecutor.Method, Stage> newexecutorsMap = new HashMap<CommandExecutor.Method, Stage>(); Document document = getResourceLoader().getDocument(resource); Map<Stage, Integer> totals = new EnumMap<Stage, Integer>(Stage.class); if (document != null) { org.w3c.dom.NodeList ellist = document.getDocumentElement().getChildNodes(); Stage prevStage = Stage.RECOGNIZER; for (int i = 0; i <= ellist.getLength(); i++) { if (ellist.item(i) instanceof Element) { Element el = (Element) ellist.item(i); if (el.getTagName().equals("localhost")) { int max = Integer.parseInt(el.getAttribute("max_simultaneous_transcoders")); Stage s = Stage.valueOf(el.getAttribute("stage").toUpperCase()); Integer t = totals.get(s); if (t == null) t = 0; t += max; totals.put(s, t); for (int j = 1; j <= max; j++) { newexecutorsMap.put(new CommandExecutor.Method(), s); } } else if (el.getTagName().equals("server")) { int max = Integer.parseInt(el.getAttribute("max_simultaneous_transcoders")); Stage s = Stage.valueOf(el.getAttribute("stage").toUpperCase()); Integer t = totals.get(s); if (t == null) t = 0; t += max; totals.put(s, t); String host = el.getAttribute("host"); int port = Integer.parseInt(el.getAttribute("port")); for (int j = 1; j <= max; j++) { newexecutorsMap.put(new CommandExecutor.Method(host, port), s); } } } } for (Map.Entry<Stage, Integer> e : totals.entrySet()) { threadPools.get(e.getKey()).setCorePoolSize(e.getValue()); threadPools.get(e.getKey()).setMaximumPoolSize(e.getValue()); } } else { LOG.warn("No " + resource); } synchronized (executorsMap) { executorsMap.clear(); executorsMap.putAll(newexecutorsMap); } LOG.service( "Reading of configuration file " + resource + " successfull. Executors " + executorsMap + ". Max simultaneous transcoders: " + totals); } catch (Exception e) { LOG.error( e.getClass() + " " + e.getMessage() + " In " + resource + " Executors now " + executorsMap + " (not changed)", e); } }
public CUfunction getKernelFunction(Kernel f) { CUfunction function = kernels.get(f); if (function == null) throw new CudaException("No such function " + f); return function; }
private void initFunction(CUmodule module, Kernel name) { CUfunction function = new CUfunction(); JCudaDriver.cuModuleGetFunction(function, module, name.name()); kernels.put(name, function); }