Search in sources :

Example 1 with TableDescription

use of org.nustaq.reallive.api.TableDescription in project kontraktor by RuedigerMoeller.

the class DataClient method connect.

public IPromise connect(DataCfg config, TableSpaceActor[] shards, ServiceActor hostingService) {
    this.config = config;
    this.hostingService = hostingService;
    this.shards = shards;
    syncTableAccess = new HashMap();
    tableSharding = new TableSpaceSharding(shards, key -> Math.abs(key.hashCode()) % shards.length);
    tableSharding.init().await();
    TableDescription[] schema = config.getSchema();
    return all(schema.length, i -> {
        Promise p = new Promise();
        tableSharding.createOrLoadTable(schema[i]).then((r, e) -> {
            if (r != null) {
                syncTableAccess.put(schema[i].getName(), r);
            }
            p.complete(r, e);
        });
        return p;
    });
}
Also used : Record(org.nustaq.reallive.api.Record) Arrays(java.util.Arrays) TableSpaceActor(org.nustaq.reallive.impl.tablespace.TableSpaceActor) Promise(org.nustaq.kontraktor.Promise) HashMap(java.util.HashMap) RealLiveTable(org.nustaq.reallive.api.RealLiveTable) Callback(org.nustaq.kontraktor.Callback) TimeUnit(java.util.concurrent.TimeUnit) TableDescription(org.nustaq.reallive.api.TableDescription) CountDownLatch(java.util.concurrent.CountDownLatch) IPromise(org.nustaq.kontraktor.IPromise) java.io(java.io) TableSpaceSharding(org.nustaq.reallive.impl.tablespace.TableSpaceSharding) ServiceActor(org.nustaq.kontraktor.services.ServiceActor) CallerSideMethod(org.nustaq.kontraktor.annotations.CallerSideMethod) Log(org.nustaq.kontraktor.util.Log) FSTConfiguration(org.nustaq.serialization.FSTConfiguration) Actors(org.nustaq.kontraktor.Actors) RLPredicate(org.nustaq.reallive.api.RLPredicate) ClusteredTableSpaceClient(org.nustaq.reallive.impl.tablespace.ClusteredTableSpaceClient) Promise(org.nustaq.kontraktor.Promise) IPromise(org.nustaq.kontraktor.IPromise) HashMap(java.util.HashMap) TableSpaceSharding(org.nustaq.reallive.impl.tablespace.TableSpaceSharding) TableDescription(org.nustaq.reallive.api.TableDescription)

Example 2 with TableDescription

use of org.nustaq.reallive.api.TableDescription in project kontraktor by RuedigerMoeller.

the class DefaultSessionStorage method init.

public IPromise init(Config cfg) {
    Promise p = new Promise();
    // FIXME: fireasync and await both
    try {
        String dataDir = cfg.getDataDir();
        new File(dataDir).mkdirs();
        IPromise _sessionId2UserKey = EmbeddedRealLive.get().createTable(new TableDescription().keyLen(64).sizeMB(cfg.getSizeSessionIdsMB()).name("sessionid2userkey").storageType(TableDescription.StorageType.PERSIST), dataDir);
        IPromise _userData = EmbeddedRealLive.get().createTable(new TableDescription().keyLen(64).sizeMB(cfg.getSizeSessionIdsMB()).name("userdata").storageType(TableDescription.StorageType.PERSIST), dataDir);
        Actors.all(_sessionId2UserKey, _userData).then(() -> {
            sessionId2UserKey = (RealLiveTable) _sessionId2UserKey.get();
            userData = (RealLiveTable) _userData.get();
            p.resolve();
        });
    } catch (Exception e) {
        Log.Warn(this, e);
        return new Promise(null, e);
    }
    return p;
}
Also used : File(java.io.File) TableDescription(org.nustaq.reallive.api.TableDescription)

Aggregations

TableDescription (org.nustaq.reallive.api.TableDescription)2 java.io (java.io)1 File (java.io.File)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 TimeUnit (java.util.concurrent.TimeUnit)1 Actors (org.nustaq.kontraktor.Actors)1 Callback (org.nustaq.kontraktor.Callback)1 IPromise (org.nustaq.kontraktor.IPromise)1 Promise (org.nustaq.kontraktor.Promise)1 CallerSideMethod (org.nustaq.kontraktor.annotations.CallerSideMethod)1 ServiceActor (org.nustaq.kontraktor.services.ServiceActor)1 Log (org.nustaq.kontraktor.util.Log)1 RLPredicate (org.nustaq.reallive.api.RLPredicate)1 RealLiveTable (org.nustaq.reallive.api.RealLiveTable)1 Record (org.nustaq.reallive.api.Record)1 ClusteredTableSpaceClient (org.nustaq.reallive.impl.tablespace.ClusteredTableSpaceClient)1 TableSpaceActor (org.nustaq.reallive.impl.tablespace.TableSpaceActor)1 TableSpaceSharding (org.nustaq.reallive.impl.tablespace.TableSpaceSharding)1