|
Apache CXF example source code file (AbstractStaticFailoverStrategy.java)
The Apache CXF AbstractStaticFailoverStrategy.java source code/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.apache.cxf.clustering; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import javax.xml.namespace.QName; import org.apache.cxf.common.logging.LogUtils; import org.apache.cxf.endpoint.Endpoint; import org.apache.cxf.message.Exchange; import org.apache.cxf.service.model.EndpointInfo; import org.apache.cxf.service.model.ServiceInfo; /** * Failover strategy based on a static cluster represented by * multiple endpoints associated with the same service instance. */ public abstract class AbstractStaticFailoverStrategy implements FailoverStrategy { private static final Logger LOG = LogUtils.getL7dLogger(AbstractStaticFailoverStrategy.class); private List<String> alternateAddresses; public void setAlternateAddresses(List<String> alternateAddresses) { this.alternateAddresses = alternateAddresses; } /** * Get the alternate addresses for this invocation. * * @param exchange the current Exchange * @return a List of alternate addresses if available */ public List<String> getAlternateAddresses(Exchange exchange) { return alternateAddresses != null ? new ArrayList<String>(alternateAddresses) : null; } /** * Select one of the alternate addresses for a retried invocation. * * @param a List of alternate addresses if available * @return the selected address */ public String selectAlternateAddress(List<String> alternates) { String selected = null; if (alternates != null && alternates.size() > 0) { selected = getNextAlternate(alternates); LOG.log(Level.WARNING, "FAILING_OVER_TO_ADDRESS_OVERRIDE", selected); } else { LOG.warning("NO_ALTERNATE_TARGETS_REMAIN"); } return selected; } /** * Get the alternate endpoints for this invocation. * * @param exchange the current Exchange * @return a List of alternate endpoints if available */ public List<Endpoint> getAlternateEndpoints(Exchange exchange) { return getEndpoints(exchange, false); } /** * Select one of the alternate endpoints for a retried invocation. * * @param a List of alternate endpoints if available * @return the selected endpoint */ public Endpoint selectAlternateEndpoint(List<Endpoint> alternates) { Endpoint selected = null; if (alternates != null && alternates.size() > 0) { selected = getNextAlternate(alternates); LOG.log(Level.WARNING, "FAILING_OVER_TO_ALTERNATE_ENDPOINT", new Object[] {selected.getEndpointInfo().getName(), selected.getEndpointInfo().getAddress()}); } else { LOG.warning("NO_ALTERNATE_TARGETS_REMAIN"); } return selected; } /** * Get the endpoints for this invocation. * * @param exchange the current Exchange * @param acceptCandidatesWithSameAddress true to accept candidates with the same address * @return a List of alternate endpoints if available */ protected List<Endpoint> getEndpoints(Exchange exchange, boolean acceptCandidatesWithSameAddress) { Endpoint endpoint = exchange.get(Endpoint.class); Collection<ServiceInfo> services = endpoint.getService().getServiceInfos(); QName currentBinding = endpoint.getBinding().getBindingInfo().getName(); List<Endpoint> alternates = new ArrayList Other Apache CXF examples (source code examples)Here is a short list of links related to this Apache CXF AbstractStaticFailoverStrategy.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.