/** * @param name configuration name * @param timeout in millis * @return Configuration object or null */ public static Configuration getConfiguration (String name, long timeout) { return (Configuration) NameRegistrar.get(PREFIX + name, timeout); } }
/** * associates this ISOServer with a name using NameRegistrar * @param name name to register * @see NameRegistrar */ public void setName (String name) { this.name = name; NameRegistrar.register ("server."+name, this); } /**
protected void stopService () throws Exception { NameRegistrar.unregister (poolName); } protected void destroyService () throws Exception {
private void registerQ2() { synchronized (Q2.class) { for (int i=0; ; i++) { String key = name + (i > 0 ? "-" + i : ""); if (NameRegistrar.getIfExists(key) == null) { NameRegistrar.register(key, this); break; } } } }
public void setConfiguration(Configuration cfg) throws ConfigurationException { maxSize = cfg.getInt ("size", DEFAULT_SIZE); if (name != null) NameRegistrar.unregister (name); name = cfg.get ("name", null); if (name != null) NameRegistrar.register (name, this); } public void addListener (final LogListener listener) {
private void showTMs(CLIContext cli) { NameRegistrar nr = NameRegistrar.getInstance(); int maxw = 0; Iterator iter = NameRegistrar.getAsMap().entrySet().iterator(); StringBuilder sb = new StringBuilder("available transaction managers:"); while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); String key = (String) entry.getKey(); if (entry.getValue() instanceof TransactionManager) { sb.append(' '); sb.append(key); } } cli.println(sb.toString()); }
public void run() { String key = "testKey" + counter; String value = "testValue" + counter; assertThat(NameRegistrar.getIfExists(key), is(nullValue())); NameRegistrar.register(key, value); try { String actualValue = (String) NameRegistrar.get(key); assertThat(actualValue, is(value)); } catch (NotFoundException e) { fail("key not found: " + key); } NameRegistrar.unregister(key); // Uncomment the sysout below to show that test were not // completed in order, the numbers should be interleaved // (not an ordered list) to hopefully show // the threads had the opportunity to step on each other; // i.e. thread safety of operations (and not just of Sysout!). // If it were to run too fast, can insert a Thread.sleep // part way through - say, after the register step above for // 200 milliseconds. // // System.out.println("done: "+ key); } });
@Test(expected = NameRegistrar.NotFoundException.class) public void testUnregister() throws Exception { NameRegistrar.register("test3", "someTest3Value"); assertThat(NameRegistrar.get("test3"), is("someTest3Value")); NameRegistrar.unregister("test3"); NameRegistrar.get("test3"); }
@Test public void testStopService_NoTerminationTimeout() throws Exception { executor = mock(ThreadPoolExecutor.class); NameRegistrar.register(qbean.getRegistrationName(), executor); ThreadPoolExecutor expected = NameRegistrar.get(qbean.getRegistrationName()); assertSame(expected, executor); when( executor.awaitTermination(Mockito.anyLong(), Mockito.any(TimeUnit.class))).thenReturn(true); qbean.stopService(); expected = NameRegistrar.getIfExists(qbean.getRegistrationName()); assertNull(expected); }
@Test public void testStaticGetThreadPoolExecutor() throws NotFoundException { executor = new DummyThreadPoolExecutor(1, 1, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<>(1) ); NameRegistrar.register(qbean.getRegistrationName(), executor); ThreadPoolExecutor expected = NameRegistrar.get(qbean.getRegistrationName()); assertSame(expected, executor); expected = QThreadPoolExecutor.getThreadPoolExecutor(QBEAN_DEFAULT_NAME); assertSame(expected, executor); }
public void run () { try { Interpreter bsh = initBSH (); mux = (MUX) NameRegistrar.get ("mux." + cfg.get ("mux")); List suite = initSuite (getPersist().getChild ("test-suite")); runSuite (suite, mux, bsh); } catch (NameRegistrar.NotFoundException e) { LogEvent evt = getLog().createError (); evt.addMessage (e); evt.addMessage (NameRegistrar.getInstance()); Logger.log (evt); } catch (Throwable t) { getLog().error (t); } if (cfg.getBoolean ("shutdown")) getServer().shutdown(); } private void runSuite (List suite, MUX mux, Interpreter bsh)
public static Q2 getQ2() { return (Q2) NameRegistrar.getIfExists(JMX_NAME); } public static Q2 getQ2(long timeout) {
public void dump (PrintStream p, String indent) { String newIndent = indent + " "; Runtime r = Runtime.getRuntime(); p.println (indent + "--- memory ---"); p.println (newIndent+" freeMemory="+r.freeMemory()); p.println (newIndent+"totalMemory="+r.totalMemory()); p.println (newIndent+"inUseMemory="+(r.totalMemory()-r.freeMemory())); p.println (""); p.println (indent + "--- threads ---"); p.println (newIndent+" delay="+delay+" ms"); p.println (newIndent+" threads="+Thread.activeCount()); showThreadGroup (Thread.currentThread().getThreadGroup(), p, newIndent); p.println (""); NameRegistrar.getInstance().dump (p, indent); } public void setLogger (Logger logger, String realm) {
public Map getRegistry () { return NameRegistrar.getAsMap(); } }
@Test public void testGetInstance() throws Throwable { NameRegistrar result = NameRegistrar.getInstance(); assertThat(result, is(sameInstance(NameRegistrar.getInstance()))); }
@Override public void exec(CLIContext cli, String[] args) throws Exception { cs = NameRegistrar.getIfExists("crypto-service"); if (args.length != 2) { usage(cli); if (cs == null) cli.println ("'crypto-service' not registered"); return; } encrypt(cli, args[1]); }
private void showLoggers(CLIContext cli) { NameRegistrar nr = NameRegistrar.getInstance(); int maxw = 0; Iterator iter = NameRegistrar.getAsMap().entrySet().iterator(); StringBuilder sb = new StringBuilder("available loggers:"); while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); String key = (String) entry.getKey(); if (key.startsWith("logger.") && entry.getValue() instanceof Logger) { sb.append(' '); sb.append(key.substring(7)); } } cli.println(sb.toString()); } }
@Test public void testDumpWithDetail() throws Throwable { ByteArrayOutputStream out = new ByteArrayOutputStream(); NameRegistrar.getInstance().dump(new PrintStream(out), "+", WITH_DETAIL); assertThat( out.toString(), allOf(containsString("name-registrar:" + System.getProperty("line.separator")), containsString("test1"), containsString("test2"))); }
private Map<String, Object> muxes () { List<Object> muxes = NameRegistrar.getAsMap().entrySet() .stream().filter(e -> e.getValue() instanceof QMUX && e.getKey().startsWith("mux.")) .map(e -> muxInfo((QMUX) e.getValue())) .collect(Collectors.toList()); Map<String,Object> wrapper = new HashMap<>(); wrapper.put("mux", muxes); return wrapper; }
/** * @return MUX with name using NameRegistrar * @throws NameRegistrar.NotFoundException * @see NameRegistrar */ public static MUX getMUX (String name) throws NameRegistrar.NotFoundException { return (MUX) NameRegistrar.get ("mux."+name); }