public static Q2 getQ2() { return (Q2) NameRegistrar.getIfExists(JMX_NAME); } public static Q2 getQ2(long timeout) {
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; } } } }
@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]); }
@Override public void exec(CLIContext cli, String[] args) throws Exception { cs = NameRegistrar.getIfExists("crypto-service"); if (args.length != 3) { usage(cli); if (cs == null) cli.println ("'crypto-service' not registered"); return; } try { decrypt(cli, args[1], args[2]); } catch (Exception e) { cli.println (e.getMessage()); } }
@Test public void testGetIfExistsWithNotFoundKey() throws Exception { String value = NameRegistrar.getIfExists("NonexistentKey"); assertThat(value, is(nullValue())); }
@Override public void exec(CLIContext cli, String[] args) throws Exception { cs = NameRegistrar.getIfExists("crypto-service"); if (args.length != 1) { usage(cli); return; } if (cs == null) cli.println ("'crypto-service' not registered"); else { try { cli.println(unlock(cli) ? "Unlocked" : "Invalid password/keystore"); } catch (Exception e) { cli.println(e.getMessage()); e.printStackTrace(); } } }
@Test public void testGetIfExists() throws Throwable { String value = NameRegistrar.getIfExists("test2"); assertThat(value, is("testValue2")); }
@Override public void exec(CLIContext cli, String[] args) throws Exception { cs = NameRegistrar.getIfExists("crypto-service"); if (args.length != 1) { usage(cli); if (cs == null) cli.println ("'crypto-service' not registered"); return; } cs.lock(); if (!cs.isLocked()) cli.println("Locked"); }
@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); }
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); } });
public synchronized void initialize() throws ConfigurationException, NotFoundException { if (getPackager() == null && name != null) { Object entry = NameRegistrar.getIfExists(name); if (entry instanceof QServer) { QServer server = (QServer) entry; Object entry = NameRegistrar.getIfExists(name); if (entry instanceof QServer) { QServer server = (QServer) entry;
MUX mux = NameRegistrar.getIfExists (muxName); if (mux == null) return result.fail(CMF.MISCONFIGURED_ENDPOINT, Caller.info(), "MUX '%s' not found", muxName).FAIL();