Search in sources :

Example 1 with TableSpaceSharding

use of org.nustaq.reallive.impl.tablespace.TableSpaceSharding 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 TableSpaceSharding

use of org.nustaq.reallive.impl.tablespace.TableSpaceSharding in project kontraktor by RuedigerMoeller.

the class TableSpaceTest method simpleSharded.

@Test
public void simpleSharded() {
    TableSpaceActor[] spaces = { Actors.AsActor(TableSpaceActor.class), Actors.AsActor(TableSpaceActor.class) };
    for (int i = 0; i < spaces.length; i++) {
        TableSpaceActor space = spaces[i];
        space.init();
    }
    TableSpaceSharding ts = new TableSpaceSharding(spaces, key -> Math.abs(key.hashCode()) % spaces.length);
    Assert.assertTrue(runSimpleTest(ts, () -> createShardedTableDescription()) == EXPECT_SIMPLECOUNT);
    ts.shutDown().await();
}
Also used : TableSpaceSharding(org.nustaq.reallive.impl.tablespace.TableSpaceSharding) TableSpaceActor(org.nustaq.reallive.impl.tablespace.TableSpaceActor) Test(org.junit.Test)

Example 3 with TableSpaceSharding

use of org.nustaq.reallive.impl.tablespace.TableSpaceSharding in project kontraktor by RuedigerMoeller.

the class TableSpaceTest method simpleShardedNoServer.

@Test
public void simpleShardedNoServer() {
    TableSpaceActor[] spaces = { null, null };
    spaces[0] = (TableSpaceActor) new TCPConnectable(TableSpaceActor.class, "localhost", 5432).connect((disc, err) -> System.out.println("client disc " + disc + " " + err)).await();
    spaces[1] = (TableSpaceActor) new TCPConnectable(TableSpaceActor.class, "localhost", 5433).connect((disc, err) -> System.out.println("client disc " + disc + " " + err)).await();
    for (int i = 0; i < spaces.length; i++) {
        TableSpaceActor space = spaces[i];
        space.init();
    }
    TableSpaceSharding ts = new TableSpaceSharding(spaces, key -> Math.abs(key.hashCode()) % spaces.length);
    Assert.assertTrue(runSimpleTest(ts, () -> createShardedTableDescription()) == EXPECT_SIMPLECOUNT);
    ts.shutDown().await();
}
Also used : TCPConnectable(org.nustaq.kontraktor.remoting.tcp.TCPConnectable) IntStream(java.util.stream.IntStream) org.nustaq.reallive.api(org.nustaq.reallive.api) Ignore(org.junit.Ignore) TableSpaceActor(org.nustaq.reallive.impl.tablespace.TableSpaceActor) Assert(junit.framework.Assert) TableSpaceSharding(org.nustaq.reallive.impl.tablespace.TableSpaceSharding) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Actors(org.nustaq.kontraktor.Actors) TCPNIOPublisher(org.nustaq.kontraktor.remoting.tcp.TCPNIOPublisher) Test(org.junit.Test) Supplier(java.util.function.Supplier) TCPConnectable(org.nustaq.kontraktor.remoting.tcp.TCPConnectable) TableSpaceSharding(org.nustaq.reallive.impl.tablespace.TableSpaceSharding) TableSpaceActor(org.nustaq.reallive.impl.tablespace.TableSpaceActor) Test(org.junit.Test)

Aggregations

TableSpaceActor (org.nustaq.reallive.impl.tablespace.TableSpaceActor)3 TableSpaceSharding (org.nustaq.reallive.impl.tablespace.TableSpaceSharding)3 Test (org.junit.Test)2 Actors (org.nustaq.kontraktor.Actors)2 java.io (java.io)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Supplier (java.util.function.Supplier)1 IntStream (java.util.stream.IntStream)1 Assert (junit.framework.Assert)1 Ignore (org.junit.Ignore)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 TCPConnectable (org.nustaq.kontraktor.remoting.tcp.TCPConnectable)1 TCPNIOPublisher (org.nustaq.kontraktor.remoting.tcp.TCPNIOPublisher)1