private List<Throwable> doFirstMatchDiscovery(AbstractInvocationContext context, final FilterSpec filterSpec, final FilterSpec fallbackFilterSpec) { Logs.INVOCATION.tracef("Performing first-match discovery(locator = %s, weak affinity = %s, filter spec = %s)", context.getLocator(), context.getWeakAffinity(), filterSpec); final List<Throwable> problems; final Set<URI> set = context.getAttachment(BL_KEY); try (final ServicesQueue queue = discover(filterSpec)) { ServiceURL serviceURL; context.setTargetAffinity(new NodeAffinity(nodeValue.toString())); } else { context.setTargetAffinity(URIAffinity.forUri(location)); context.setDestination(location); Logs.INVOCATION.tracef("Performed first-match discovery(target affinity = %s, destination = %s)", context.getTargetAffinity(), context.getDestination()); return queue.getProblems(); assert context.getLocator().getAffinity() instanceof ClusterAffinity; Logs.INVOCATION.tracef("Performed first-match discovery, no match, falling back to cluster discovery"); return merge(problems, doClusterDiscovery(context, fallbackFilterSpec));
private List<Throwable> doAnyDiscovery(AbstractInvocationContext context, final FilterSpec filterSpec, final EJBLocator<?> locator) { Logs.INVOCATION.tracef("Performing any discovery(locator = %s, weak affinity = %s, filter spec = %s)", context.getLocator(), context.getWeakAffinity(), filterSpec); final List<Throwable> problems; final Set<URI> blacklist = context.getAttachment(BL_KEY); final Map<URI, String> nodes = new HashMap<>(); final Map<String, URI> uris = new HashMap<>(); } else if (nodeless == 0) { DeploymentNodeSelector selector = context.getClientContext().getDeploymentNodeSelector(); nodeName = selector.selectNode(nodes.values().toArray(NO_STRINGS), locator.getAppName(), locator.getModuleName(), locator.getDistinctName()); if (nodeName == null) { context.setDestination(location); if (nodeName != null) context.setTargetAffinity(new NodeAffinity(nodeName)); return problems;
private IoFuture<ConnectionPeerIdentity> getConnection(final AbstractInvocationContext context, final URI target, @NotNull AuthenticationContext authenticationContext) throws Exception { Affinity affinity = context.getLocator().getAffinity(); String cluster = (affinity instanceof ClusterAffinity) ? ((ClusterAffinity) affinity).getClusterName() : context.getInitialCluster(); if (cluster != null) { return doPrivileged((PrivilegedAction<IoFuture<ConnectionPeerIdentity>>) () -> discoveredNodeRegistry.getConnectedIdentityUsingClusterEffective(Endpoint.getCurrent(), target, "ejb", "jboss", authenticationContext, cluster)); } return doPrivileged((PrivilegedAction<IoFuture<ConnectionPeerIdentity>>) () -> Endpoint.getCurrent().getConnectedIdentity(target, "ejb", "jboss", authenticationContext)); } }
private void processMissingTarget(final AbstractInvocationContext context) { final URI destination = context.getDestination(); if (destination == null || context.getTargetAffinity() == Affinity.LOCAL) { // nothing we can/should do. return; } // Oops, we got some wrong information! addBlackListedDestination(context, destination); // clear the weak affinity so that cluster invocations can be re-targeted. context.setWeakAffinity(Affinity.NONE); context.setTargetAffinity(null); context.setDestination(null); context.requestRetry(); }
private void processMissingTarget(final AbstractInvocationContext context) { final URI destination = context.getDestination(); if (destination == null || context.getTargetAffinity() == Affinity.LOCAL) { // some later interceptor cleared it out on us return; } // Oops, we got some wrong information! addBlackListedDestination(context, destination); final EJBLocator<?> locator = context.getLocator(); if (! (locator.getAffinity() instanceof ClusterAffinity)) { // it *was* "none" affinity, but it has been relocated; locate it back again context.setLocator(locator.withNewAffinity(Affinity.NONE)); } // clear the weak affinity so that cluster invocations can be re-targeted. context.setWeakAffinity(Affinity.NONE); context.setTargetAffinity(null); context.setDestination(null); context.requestRetry(); } }
static boolean addBlackListedDestination(AbstractInvocationContext context, URI destination) { Assert.checkNotNullParam("context", context); if (destination != null) { Set<URI> set = context.getAttachment(BL_KEY); if (set == null) { final Set<URI> appearing = context.putAttachmentIfAbsent(BL_KEY, set = new HashSet<>()); if (appearing != null) { set = appearing; } } Logs.INVOCATION.tracef("Blacklisting destination (locator = %s, weak affinity = %s, missing target = %s)", context.getLocator(), context.getWeakAffinity(), destination); return set.add(destination); } else { return false; } }
private List<Throwable> executeDiscovery(AbstractInvocationContext context) { assert context.getDestination() == null; final EJBLocator<?> locator = context.getLocator(); final Affinity affinity = locator.getAffinity(); final Affinity weakAffinity = context.getWeakAffinity(); if (! isBlackListed(context, affinity.getUri())) { context.setDestination(affinity.getUri()); context.setTargetAffinity(affinity); context.setDestination(weakAffinity.getUri()); context.setTargetAffinity(weakAffinity); } else if (weakAffinity instanceof URIAffinity || weakAffinity == Affinity.LOCAL) { context.setDestination(weakAffinity.getUri()); context.setTargetAffinity(weakAffinity); return null; } else {
private void removeNode(final AbstractInvocationContext context) { final Affinity targetAffinity = context.getTargetAffinity(); if (targetAffinity instanceof NodeAffinity) { final RemoteEJBReceiver ejbReceiver = context.getClientContext().getAttachment(RemoteTransportProvider.ATTACHMENT_KEY); if (ejbReceiver != null) { final EJBClientChannel ejbClientChannel = context.getAttachment(RemoteEJBReceiver.EJBCC_KEY); if (ejbClientChannel != null) { final NodeInformation nodeInformation = ejbReceiver.getDiscoveredNodeRegistry().getNodeInformation(((NodeAffinity) targetAffinity).getNodeName()); if (nodeInformation != null) { nodeInformation.removeModule(ejbClientChannel, context.getLocator().getIdentifier().getModuleIdentifier()); } } } } } }
private Application updateOrFollowApplication(AbstractInvocationContext context, ConcurrentMap<Application, URI> applications, boolean register) { URI destination = context.getDestination(); if (destination != null) { EJBIdentifier identifier = context.getLocator().getIdentifier(); Application application = toApplication(identifier); URI existing = applications.putIfAbsent(application, destination); if (existing != null) { // Someone else set a mapping, use it instead context.setDestination(existing); } else { if (register) { context.putAttachment(APPLICATION, application); } return application; } } else { Logs.TXN.trace("Failed assertion: a destination was supposed ot be present but wasn't"); } return null; }
private static boolean setDestination(final AbstractInvocationContext context, final NamingProvider namingProvider) { if (namingProvider != null) { final URI destination = context.getDestination(); if (destination == null) { final EJBLocator<?> locator = context.getLocator(); if (locator.getAffinity() == Affinity.NONE) { final Affinity weakAffinity = context.getWeakAffinity(); if (weakAffinity == Affinity.NONE) { return setNamingDestination(context, namingProvider); } } } } return true; }
private void setupStickinessIfRequired(AbstractInvocationContext context, boolean propagate, AbstractTransaction transaction) { ConcurrentMap<Application, URI> applications = null; if (transaction instanceof RemoteTransaction) { final URI location = ((RemoteTransaction) transaction).getLocation(); // we can only route this request to one place; do not load-balance if (location != null) { context.setDestination(location); setupSessionAffinitiesIfNeeded(context); } } else if (transaction instanceof LocalTransaction && propagate){ applications = getOrCreateApplicationMap(transaction); URI destination = getApplicationAssociation(applications, context); if (destination != null) { context.setDestination(destination); setupSessionAffinitiesIfNeeded(context); } else { if (applications.size() > 0) { context.putAttachment(PREFERRED_DESTINATIONS, applications.values()); } context.putAttachment(APPLICATIONS, applications); } } }
static boolean isBlackListed(AbstractInvocationContext context, URI destination) { final Set<URI> blacklist = context.getAttachment(BL_KEY); return blacklist != null && blacklist.contains(destination); }
private static void disassociateRemoteTxIfPossible(AbstractInvocationContext context) { AbstractTransaction transaction = context.getTransaction(); if (transaction instanceof RemoteTransaction) { RemoteTransaction remote = (RemoteTransaction) transaction; if (!remote.tryClearLocation()) { Logs.TXN.tracef("Could not disassociate remote transaction (already in-use or completed) from %s", remote.getLocation()); } } }
private static URI getApplicationAssociation(ConcurrentMap<Application, URI> applications, AbstractInvocationContext context) { return applications.get(toApplication(context.getLocator().getIdentifier())); }
private void processMissingTarget(final AbstractInvocationContext context) { final URI destination = context.getDestination(); if (destination == null || context.getTargetAffinity() == Affinity.LOCAL) { // some later interceptor cleared it out on us return; } // Oops, we got some wrong information! addBlackListedDestination(context, destination); final EJBLocator<?> locator = context.getLocator(); if (! (locator.getAffinity() instanceof ClusterAffinity)) { // it *was* "none" affinity, but it has been relocated; locate it back again context.setLocator(locator.withNewAffinity(Affinity.NONE)); } // clear the weak affinity so that cluster invocations can be re-targeted. context.setWeakAffinity(Affinity.NONE); context.setTargetAffinity(null); context.setDestination(null); context.requestRetry(); } }
private void processMissingTarget(final AbstractInvocationContext context) { final URI destination = context.getDestination(); if (destination == null || context.getTargetAffinity() == Affinity.LOCAL) { // nothing we can/should do. return; } // Oops, we got some wrong information! addBlackListedDestination(context, destination); // clear the weak affinity so that cluster invocations can be re-targeted. context.setWeakAffinity(Affinity.NONE); context.setTargetAffinity(null); context.setDestination(null); context.requestRetry(); }
private List<Throwable> executeDiscovery(AbstractInvocationContext context) { assert context.getDestination() == null; final EJBLocator<?> locator = context.getLocator(); final Affinity affinity = locator.getAffinity(); final Affinity weakAffinity = context.getWeakAffinity(); if (! isBlackListed(context, affinity.getUri())) { context.setDestination(affinity.getUri()); context.setTargetAffinity(affinity); context.setDestination(weakAffinity.getUri()); context.setTargetAffinity(weakAffinity); } else if (weakAffinity instanceof URIAffinity || weakAffinity == Affinity.LOCAL) { context.setDestination(weakAffinity.getUri()); context.setTargetAffinity(weakAffinity); return null; } else {
private void removeNode(final AbstractInvocationContext context) { final Affinity targetAffinity = context.getTargetAffinity(); if (targetAffinity instanceof NodeAffinity) { final RemoteEJBReceiver ejbReceiver = context.getClientContext().getAttachment(RemoteTransportProvider.ATTACHMENT_KEY); if (ejbReceiver != null) { final EJBClientChannel ejbClientChannel = context.getAttachment(RemoteEJBReceiver.EJBCC_KEY); if (ejbClientChannel != null) { final NodeInformation nodeInformation = ejbReceiver.getDiscoveredNodeRegistry().getNodeInformation(((NodeAffinity) targetAffinity).getNodeName()); if (nodeInformation != null) { nodeInformation.removeModule(ejbClientChannel, context.getLocator().getIdentifier().getModuleIdentifier()); } } } } } }
static boolean addBlackListedDestination(AbstractInvocationContext context, URI destination) { Assert.checkNotNullParam("context", context); if (destination != null) { Set<URI> set = context.getAttachment(BL_KEY); if (set == null) { final Set<URI> appearing = context.putAttachmentIfAbsent(BL_KEY, set = new HashSet<>()); if (appearing != null) { set = appearing; } } Logs.INVOCATION.tracef("Blacklisting destination (locator = %s, weak affinity = %s, missing target = %s)", context.getLocator(), context.getWeakAffinity(), destination); return set.add(destination); } else { return false; } }
private Application updateOrFollowApplication(AbstractInvocationContext context, ConcurrentMap<Application, URI> applications, boolean register) { URI destination = context.getDestination(); if (destination != null) { EJBIdentifier identifier = context.getLocator().getIdentifier(); Application application = toApplication(identifier); URI existing = applications.putIfAbsent(application, destination); if (existing != null) { // Someone else set a mapping, use it instead context.setDestination(existing); } else { if (register) { context.putAttachment(APPLICATION, application); } return application; } } else { Logs.TXN.trace("Failed assertion: a destination was supposed ot be present but wasn't"); } return null; }