use of org.apache.synapse.endpoints.Endpoint in project wso2-synapse by wso2.
the class SALSessions method getEndpoints.
/*
* Helper method to get a list of endpoints from a list of endpoint name maps -
* This is for clustered env.
*/
private List<Endpoint> getEndpoints(List<String> endpointNames, String root) {
if (endpointNames == null || endpointNames.isEmpty()) {
handleException("Invalid session - path cannot be null.");
}
if (log.isDebugEnabled()) {
log.debug("Retrieving endpoint sequence for path " + endpointNames);
}
List<Endpoint> endpoints = new ArrayList<Endpoint>();
// to each time calculate
if (namesToEndpointsMap.containsKey(endpointNames)) {
endpoints.addAll(namesToEndpointsMap.get(endpointNames));
return endpoints;
}
Map<String, Endpoint> map = childEndpoints.get(root);
assert endpointNames != null;
for (String endpointName : endpointNames) {
Endpoint endpoint = null;
if (map != null) {
endpoint = map.get(endpointName);
if (endpoint == null || endpoints.contains(endpoint)) {
map = childEndpoints.get(endpointName);
if (map != null) {
endpoint = map.get(endpointName);
}
}
}
if (endpoint == null) {
handleException("Invalid session. Endpoint with name '" + endpointName + "' cannot found");
}
endpoints.add(endpoint);
}
// cache path(endpoint names) vs endpoint (instance) sequence
namesToEndpointsMap.put(endpointNames, endpoints);
return endpoints;
}
use of org.apache.synapse.endpoints.Endpoint in project wso2-synapse by wso2.
the class SALSessions method createSessionInformation.
/*
* Factory method to create a session information using given endpoint list, list of paths
* session id and other informations
*/
private SessionInformation createSessionInformation(MessageContext synCtx, String id, List<Endpoint> endpoints, List<String> paths) {
if (endpoints == null || endpoints.isEmpty()) {
handleException("Invalid request to create sessions . Cannot find a endpoint sequence.");
}
if (log.isDebugEnabled()) {
log.debug("Creating a session information for given session id " + id + " with endpoint sequence " + endpoints);
}
long expireTimeWindow = -1;
assert endpoints != null;
for (Endpoint endpoint : endpoints) {
if (endpoint instanceof SALoadbalanceEndpoint) {
long sessionsTimeout = ((SALoadbalanceEndpoint) endpoint).getSessionTimeout();
if (expireTimeWindow == -1) {
expireTimeWindow = sessionsTimeout;
} else if (expireTimeWindow > sessionsTimeout) {
expireTimeWindow = sessionsTimeout;
}
}
}
if (expireTimeWindow == -1) {
expireTimeWindow = synCtx.getConfiguration().getProperty(SynapseConstants.PROP_SAL_ENDPOINT_DEFAULT_SESSION_TIMEOUT, SynapseConstants.SAL_ENDPOINTS_DEFAULT_SESSION_TIMEOUT);
}
if (log.isDebugEnabled()) {
log.debug("For session with id " + id + " : expiry time interval : " + expireTimeWindow);
}
long expiryTime = System.currentTimeMillis() + expireTimeWindow;
Endpoint rootEndpoint = endpoints.get(0);
SessionInformation information = new SessionInformation(id, endpoints, expiryTime);
information.setPath(paths);
if (isClustered) {
information.setRootEndpointName(getEndpointName(rootEndpoint));
}
return information;
}
use of org.apache.synapse.endpoints.Endpoint in project wso2-synapse by wso2.
the class WeightedRoundRobin method getNextEndpoint.
public Endpoint getNextEndpoint(MessageContext synapseMessageContext, AlgorithmContext algorithmContext) {
Lock readLock = lock.readLock();
readLock.lock();
try {
if (!isThreadLocal) {
synchronized (this) {
EndpointState state = endpointStates[endpointCursor];
if (state.getCurrentWeight() == 0) {
// reset the current state
state.reset();
// go to the next endpoint
if (endpointCursor == endpointStates.length - 1) {
endpointCursor = 0;
} else {
++endpointCursor;
}
state = endpointStates[endpointCursor];
}
// we are about to use this endpoint, so decrement its current count
state.decrementCurrentWeight();
// return the endpoint corresponding to the current position
return endpoints.get(state.getEndpointPosition());
}
} else {
if (threadedAlgorithm != null) {
Algorithm algo = threadedAlgorithm.get();
int position = algo.getNextEndpoint();
return endpoints.get(position);
} else {
String msg = "Algorithm: WeightedRoundRobin algorithm not initialized properly";
log.error(msg);
throw new SynapseException(msg);
}
}
} finally {
readLock.unlock();
}
}
use of org.apache.synapse.endpoints.Endpoint in project wso2-synapse by wso2.
the class WeightedRRLCAlgorithmTest method createLoadBalanceEndpoint.
private LoadbalanceEndpoint createLoadBalanceEndpoint() {
LoadbalanceEndpoint loadbalanceEndpoint = new LoadbalanceEndpoint();
List<Endpoint> endpoints = createEndpoints();
WeightedRRLCAlgorithm algorithm = new WeightedRRLCAlgorithm();
MediatorProperty property = new MediatorProperty();
property.setName(WeightedRRLCAlgorithm.LB_WEIGHTED_RRLC_ROUNDS_PER_RECAL);
property.setValue("2");
loadbalanceEndpoint.addProperty(property);
algorithm.setEndpoints(endpoints);
algorithm.setLoadBalanceEndpoint(loadbalanceEndpoint);
loadbalanceEndpoint.setChildren(endpoints);
loadbalanceEndpoint.setAlgorithm(algorithm);
SynapseEnvironment env = new Axis2SynapseEnvironment(new ConfigurationContext(new AxisConfiguration()), new SynapseConfiguration());
loadbalanceEndpoint.init(env);
return loadbalanceEndpoint;
}
use of org.apache.synapse.endpoints.Endpoint in project wso2-synapse by wso2.
the class WeightedRRLCAlgorithmTest method createEndpoints.
private List<Endpoint> createEndpoints() {
List<Endpoint> endpoints = new ArrayList<Endpoint>();
for (int i = 0; i < hosts.length; i++) {
AddressEndpoint addressEndpoint = new AddressEndpoint();
EndpointDefinition definition = new EndpointDefinition();
definition.setAddress("http://" + hosts[i] + "/");
addressEndpoint.setDefinition(definition);
MediatorProperty property = new MediatorProperty();
property.setName(WeightedRRLCAlgorithm.LB_WEIGHTED_RRLC_WEIGHT);
property.setValue(weights[i]);
addressEndpoint.addProperty(property);
endpoints.add(addressEndpoint);
}
return endpoints;
}
Aggregations