Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2015-2022 Futeh Kao
*
* Licensed 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 net.e6tech.elements.web.federation.invocation;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import net.e6tech.elements.common.federation.Frequency;
import net.e6tech.elements.common.federation.Member;
import net.e6tech.elements.common.federation.Registry;
import net.e6tech.elements.common.resources.Initializable;
import net.e6tech.elements.common.resources.NotAvailableException;
import net.e6tech.elements.common.resources.Resources;
import net.e6tech.elements.common.util.SystemException;
import net.e6tech.elements.common.util.concurrent.Async;
import net.e6tech.elements.network.cluster.Local;
import net.e6tech.elements.web.federation.CollectiveImpl;
import net.e6tech.elements.web.federation.Service;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.Function;
@SuppressWarnings("unchecked")
public class InvokerRegistryImpl implements InvokerRegistry, Initializable {
private static Cache> cache = CacheBuilder.newBuilder()
.concurrencyLevel(32)
.initialCapacity(128)
.maximumSize(100)
.expireAfterWrite(10 * 60 * 1000L, TimeUnit.MILLISECONDS)
.build();
private CollectiveImpl collective;
private ConcurrentMap> registrations = new ConcurrentHashMap<>();
private volatile int roundRobin = new Random().nextInt(Integer.MAX_VALUE / 2);
private Executor executor = runnable -> new Thread(runnable).start();
@Override
public void start() {
}
public Executor getExecutor() {
return executor;
}
public void setExecutor(Executor executor) {
if (executor != null)
this.executor = executor;
else
this.executor = runnable -> new Thread(runnable).start();
}
public CollectiveImpl getCollective() {
return collective;
}
public void setCollective(CollectiveImpl collective) {
this.collective = collective;
InvokerRegistryAPI api = new InvokerRegistryAPI();
api.setRegistry(this);
api.setSubZero(collective.getSubZero());
Service service = new Service(this, InvokerRegistryAPI.class, api);
collective.addService(service);
}
@Override
public void shutdown() {
}
@Override
public void initialize(Resources resources) {
if (collective == null) {
throw new IllegalStateException("Federation not set.");
}
}
/**
*
* @param path fully qualified path, this is the unique key. registering to the cluster and self.
* @param invoker takes arguments and execute method call to return a value
* @return value based on provided arguments
*/
protected String register(String path, Function