use of com.cinchapi.concourse.thrift.TransactionToken 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);
}
use of com.cinchapi.concourse.thrift.TransactionToken in project concourse by cinchapi.
the class ConcourseServer method findCcl.
@Override
@TranslateClientExceptions
@VerifyAccessToken
@VerifyReadPermission
public Set<Long> findCcl(String ccl, AccessToken creds, TransactionToken transaction, String environment) throws TException {
AbstractSyntaxTree ast = compiler.parse(ccl);
AtomicSupport store = getStore(transaction, environment);
Function<Store, Set<Long>> function = $store -> ast.accept(Finder.instance(), $store);
try {
return function.apply(store);
} catch (InsufficientAtomicityException e) {
return AtomicOperations.supplyWithRetry(store, atomic -> function.apply(atomic));
}
}
use of com.cinchapi.concourse.thrift.TransactionToken in project concourse by cinchapi.
the class ConcourseServer method findKeyOperatorValuesPage.
@Override
@TranslateClientExceptions
@VerifyAccessToken
@VerifyReadPermission
public Set<Long> findKeyOperatorValuesPage(String key, Operator operator, List<TObject> values, TPage page, AccessToken creds, TransactionToken transaction, String environment) throws TException {
TObject[] tValues = values.toArray(Array.containing());
AtomicSupport store = getStore(transaction, environment);
Function<Store, Set<Long>> function = $store -> Stores.find($store, key, operator, tValues);
Set<Long> records;
try {
records = function.apply(store);
} catch (InsufficientAtomicityException e) {
records = AtomicOperations.supplyWithRetry(store, atomic -> function.apply(atomic));
}
return Paging.page(records, Pages.from(page));
}
use of com.cinchapi.concourse.thrift.TransactionToken in project concourse by cinchapi.
the class ConcourseServer method getKeyRecord.
@Override
@TranslateClientExceptions
@VerifyAccessToken
@VerifyReadPermission
public TObject getKeyRecord(String key, long record, AccessToken creds, TransactionToken transaction, String environment) throws TException {
AtomicSupport store = getStore(transaction, environment);
Function<Store, TObject> function = $store -> Iterables.getLast(Stores.select($store, key, record), TObject.NULL);
try {
return function.apply(store);
} catch (InsufficientAtomicityException e) {
return AtomicOperations.supplyWithRetry(store, atomic -> function.apply(atomic));
}
}
use of com.cinchapi.concourse.thrift.TransactionToken in project concourse by cinchapi.
the class ConcourseServer method findKeyOperatorValuesTimePage.
@Override
@TranslateClientExceptions
@VerifyAccessToken
@VerifyReadPermission
public Set<Long> findKeyOperatorValuesTimePage(String key, Operator operator, List<TObject> values, long timestamp, TPage page, AccessToken creds, TransactionToken transaction, String environment) throws TException {
TObject[] tValues = values.toArray(Array.containing());
AtomicSupport store = getStore(transaction, environment);
Function<Store, Set<Long>> function = $store -> Stores.find($store, timestamp, key, operator, tValues);
Set<Long> records;
try {
records = function.apply(store);
} catch (InsufficientAtomicityException e) {
records = AtomicOperations.supplyWithRetry(store, atomic -> function.apply(atomic));
}
return Paging.page(records, Pages.from(page));
}
Aggregations