public Binding addBinding(Binding newBinding) { ResourceAddress bindAddress = newBinding.bindAddress(); String nextProtocol = bindAddress.getOption(NEXT_PROTOCOL); if (nextProtocol == null) { if (nullNextProtocol.compareAndSet(null, newBinding)) { newBinding.incrementReferenceCount(); return null; } Binding oldBinding = nullNextProtocol.get(); if (equivalent(newBinding, oldBinding)) { oldBinding.incrementReferenceCount(); return null; } return oldBinding; } Binding oldBinding = nextProtocols.putIfAbsent(nextProtocol, newBinding); if (oldBinding == null) { newBinding.incrementReferenceCount(); } else if (equivalent(newBinding, oldBinding)) { oldBinding.incrementReferenceCount(); oldBinding = null; } return oldBinding; }
@Override public Binding addBinding(Binding newBinding) { ResourceAddress bindAddress = newBinding.bindAddress(); HttpBinding httpBinding = getBinding0(bindAddress); if (httpBinding == null) { HttpBinding newHttpBinding = new HttpBinding(bindAddress); httpBinding = bindAdditionalAddressesIfNecessary(newHttpBinding); if (httpBinding == null) { httpBinding = newHttpBinding; } } URI location = bindAddress.getResource(); String path = location.getPath(); Binding binding = httpBinding.put(path, newBinding); if (binding != null) { if (equivalent(newBinding, binding)) { binding.incrementReferenceCount(); binding = null; } } else { newBinding.incrementReferenceCount(); } return binding; }
protected final B addBinding0(B newBinding) { ResourceAddress bindAddress = newBinding.bindAddress(); B oldBinding = bindings.get(bindAddress); if (oldBinding != null) { IoHandler newHandler = newBinding.handler(); IoHandler oldHandler = oldBinding.handler(); if (oldHandler != null && newHandler != oldHandler) { throw new RuntimeException("Tried to bind address "+bindAddress+" to a different handler (old,new) = ("+oldHandler+","+newHandler+")"); } oldBinding.incrementReferenceCount(); return null; } // bind address to handler B binding = bindings.putIfAbsent(bindAddress, newBinding); if (binding != null) { if (equivalent(newBinding, binding)) { binding.incrementReferenceCount(); binding = null; } } else { newBinding.incrementReferenceCount(); } return binding; }