/** * Returns a LocalMachines associated with given context name. * * @param ctxName the context name * @return a LocalMachines associated with given context name. */ public static LocalMachines contextLocal(String ctxName) { contextLocals.putIfAbsent(ctxName, new LocalMachines( String.format("CTX[%s][$03d]", ctxName, IDS.incrementAndGet()))); return contextLocals.get(ctxName); }
/** * Returns a LocalMachines associated with current thread. * * This is often used when building a Factory, the Factory.newInstance() use it for instance. * * Thanks to client affinity, it can also be shared between client and server. * * @return a LocalMachines associated with current thread. */ public static LocalMachines threadLocal() { String id = threadLocals.get(); LocalMachines localMachines = contextLocals.get(id); if (localMachines != null) { return localMachines; } LocalMachines m = contextLocals.putIfAbsent(id, localMachines = new LocalMachines(id)); if (m != null) { return m; } else { return localMachines; } }
/** * Return LocalMachines associated with another thread, by id. * * You must know the id of the threadlocal from the other thread to be able to access it. * * From the other thread do Factory.LocalMachines.threadLocal().getId() * * @param id the other thread threadLocal() LocalMachines id * @return the LocalMachines associated with the other thread, or an empty LocalMachines which is not * automatically registered if none is found. */ public static LocalMachines threadLocalFrom(String id) { LocalMachines localMachines = contextLocals.get(id); if (localMachines != null) { return localMachines; } return new LocalMachines(id); }