@Test public void testWithStack() throws IOException, CoException { List<Ca<String, String>> caList = Arrays.asList(new CaLocal<String, String>("local"), new CaRemote<String, String>("remote")); LOG.info("index-{} name-{}", 1, caList.get(1).name()); CaStack<String, String> stack = coca.<String> withStack("test", caList); Ca<String, String> ca = stack.ca(0); Assert.assertEquals("local", ca.name()); LOG.info("index-{} name-{}", 1, stack.ca(1).name()); }
public <V> CaStack<String, V> withStack(String name, List<Ca<String, V>> ca, StackListener... listeners) throws CoException { if (stacks.containsKey(name)) { stacks.get(name).close(); } CaStack<String, V> stack = StackManager.newStack(name); for (int i = ca.size() - 1; i >= 0; i--) stack.push(ca.get(i)); for (StackListener l : listeners) { if (l instanceof WithCo) { ((WithCo) l).co(this.co); } stack.addListener(l); } stacks.put(name, stack); try { co.join(name).get(); LOG.info("{} withStack {} succ!", this.name, name); } catch (InterruptedException | ExecutionException e) { LOG.error(e.getMessage(), e); stacks.remove(name).close(); LOG.info("{} withStack {} fail!", this.name, name); } return stack; }
Coca implements Closeable, CocaConst { public <V> CaStack<String, V> withStack(String name, List<Ca<String, V>> ca, StackListener... listeners) throws CoException { if (stacks.containsKey(name)) { stacks.get(name).close(); } CaStack<String, V> stack = StackManager.newStack(name); for (int i = ca.size() - 1; i >= 0; i--) stack.push(ca.get(i)); for (StackListener l : listeners) { if (l instanceof WithCo) { ((WithCo) l).co(this.co); } stack.addListener(l); } stacks.put(name, stack); try { co.join(name).get(); LOG.info("{} withStack {} succ!", this.name, name); } catch (InterruptedException | ExecutionException e) { LOG.error(e.getMessage(), e); stacks.remove(name).close(); LOG.info("{} withStack {} fail!", this.name, name); } return stack; } }
Coca implements Closeable, CocaConst { public <V> CaStack<String, V> withStack(String name, List<Ca<String, V>> ca, StackListener... listeners) throws CoException { if (stacks.containsKey(name)) { stacks.get(name).close(); } CaStack<String, V> stack = StackManager.newStack(name); for (int i = ca.size() - 1; i >= 0; i--) stack.push(ca.get(i)); for (StackListener l : listeners) { if (l instanceof WithCo) { ((WithCo) l).co(this.co); } stack.addListener(l); } stacks.put(name, stack); try { co.join(name).get(); LOG.info("{} withStack {} succ!", this.name, name); } catch (InterruptedException | ExecutionException e) { LOG.error(e.getMessage(), e); stacks.remove(name).close(); LOG.info("{} withStack {} fail!", this.name, name); } return stack; } Coca();  Coca(String name); }
Coca implements Closeable, CocaConst { public <V> CaStack<String, V> withStack(String name, List<Ca<String, V>> ca, StackListener... listeners) throws CoException { if (stacks.containsKey(name)) { stacks.get(name).close(); } CaStack<String, V> stack = StackManager.newStack(name); for (int i = ca.size() - 1; i >= 0; i--) stack.push(ca.get(i)); for (StackListener l : listeners) { if (l instanceof WithCo) { ((WithCo) l).co(this.co); } stack.addListener(l); } stacks.put(name, stack); try { co.join(name).get(); LOG.info("{} withStack {} succ!", this.name, name); } catch (InterruptedException | ExecutionException e) { LOG.error(e.getMessage(), e); stacks.remove(name).close(); LOG.info("{} withStack {} fail!", this.name, name); } return stack; } Coca();  Coca(String name); String name(); void init(Map<String, String> conf); static final Coca newCoca(Map<String, String> conf); static final Coca newCoca(String name, Map<String, String> conf); CaStack<String, V> withStack(String name, List<Ca<String, V>> ca, StackListener... listeners); @SuppressWarnings("unchecked") CaStack<String, V> stack(String name); @Override void close(); void closeStack(String name); @Override String toString(); }
Coca implements Closeable, CocaConst { public <V> CaStack<String, V> withStack(String name, List<Ca<String, V>> ca, StackListener... listeners) throws CoException { if (stacks.containsKey(name)) { stacks.get(name).close(); } CaStack<String, V> stack = StackManager.newStack(name); for (int i = ca.size() - 1; i >= 0; i--) stack.push(ca.get(i)); for (StackListener l : listeners) { if (l instanceof WithCo) { ((WithCo) l).co(this.co); } stack.addListener(l); } stacks.put(name, stack); try { co.join(name).get(); LOG.info("{} withStack {} succ!", this.name, name); } catch (InterruptedException | ExecutionException e) { LOG.error(e.getMessage(), e); stacks.remove(name).close(); LOG.info("{} withStack {} fail!", this.name, name); } return stack; } Coca();  Coca(String name); String name(); void init(Map<String, String> conf); static final Coca newCoca(Map<String, String> conf); static final Coca newCoca(String name, Map<String, String> conf); CaStack<String, V> withStack(String name, List<Ca<String, V>> ca, StackListener... listeners); @SuppressWarnings("unchecked") CaStack<String, V> stack(String name); @Override void close(); void closeStack(String name); @Override String toString();  }