use of com.cinchapi.concourse.server.plugin.PluginManager in project concourse by cinchapi.
the class ConcourseServer method init.
/**
* Initialize this instance. This method MUST always be called after
* constructing the instance.
*
* @param port - the port on which to listen for client connections
* @param bufferStore - the location to store {@link Buffer} files
* @param dbStore - the location to store {@link Database} files
* @throws TTransportException
*/
@Internal
private void init(int port, String bufferStore, String dbStore) throws TTransportException {
Preconditions.checkState(!bufferStore.equalsIgnoreCase(dbStore), "Cannot store buffer and database files in the same directory. " + "Please check concourse.prefs.");
Preconditions.checkState(!Strings.isNullOrEmpty(Environments.sanitize(DEFAULT_ENVIRONMENT)), "Cannot initialize " + "Concourse Server with a default environment of " + "'%s'. Please use a default environment name that " + "contains only alphanumeric characters.", DEFAULT_ENVIRONMENT);
FileSystem.mkdirs(bufferStore);
FileSystem.mkdirs(dbStore);
FileSystem.lock(bufferStore);
FileSystem.lock(dbStore);
TServerSocket socket = new TServerSocket(port);
TMultiplexedProcessor processor = new TMultiplexedProcessor();
TProcessor core = new ConcourseService.Processor<>(this);
processor.registerProcessor("core", core);
processor.registerProcessor("calculate", new ConcourseCalculateService.Processor<>(this));
processor.registerProcessor("navigate", new ConcourseNavigateService.Processor<>(this));
processor.registerDefault(core);
Args args = new TThreadPoolServer.Args(socket);
args.processor(processor);
args.maxWorkerThreads(NUM_WORKER_THREADS);
args.executorService(Executors.newCachedThreadPool(new ThreadFactoryBuilder().setDaemon(true).setNameFormat("Client Worker" + " %d").build()));
// CON-530: Set a lower timeout on the ExecutorService's termination to
// prevent the server from hanging because of active threads that have
// not yet been given a task but won't allow shutdown to proceed (i.e.
// clients from a ConnectionPool).
args.stopTimeoutVal(2);
this.server = new TThreadPoolServer(args);
this.bufferStore = bufferStore;
this.dbStore = dbStore;
this.engines = Maps.newConcurrentMap();
this.users = UserService.create(ACCESS_CREDENTIALS_FILE);
this.inspector = new Inspector() {
@Override
public Role getTokenUserRole(AccessToken token) {
ByteBuffer username = users.tokens.identify(token);
return users.getRole(username);
}
@Override
public boolean isValidToken(AccessToken token) {
return users.tokens.isValid(token);
}
@Override
public boolean isValidTransaction(TransactionToken transaction) {
return transactions.containsKey(transaction);
}
@Override
public boolean tokenUserHasPermission(AccessToken token, Permission permission, String environment) {
ByteBuffer username = users.tokens.identify(token);
return users.can(username, permission, Environments.sanitize(environment));
}
};
this.httpServer = GlobalState.HTTP_PORT > 0 ? HttpServer.create(this, GlobalState.HTTP_PORT) : HttpServer.disabled();
// load the default engine
getEngine();
this.pluginManager = new PluginManager(this, GlobalState.CONCOURSE_HOME + File.separator + "plugins");
// Setup the management server
TServerSocket mgmtSocket = new TServerSocket(GlobalState.MANAGEMENT_PORT);
TSimpleServer.Args mgmtArgs = new TSimpleServer.Args(mgmtSocket);
mgmtArgs.processor(new ConcourseManagementService.Processor<>(this));
this.mgmtServer = new TSimpleServer(mgmtArgs);
}
Aggregations