Skip to content

Commit a21a1a1

Browse files
committed
Added BarrageSessionFactoryClient and application
1 parent 0beb368 commit a21a1a1

File tree

31 files changed

+405
-70
lines changed

31 files changed

+405
-70
lines changed

java-client/barrage-dagger/src/main/java/io/deephaven/client/impl/BarrageFactoryBuilderModule.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,20 @@
66
import dagger.Module;
77
import dagger.Provides;
88

9+
/**
10+
* Module that provides {@link BarrageSessionFactoryBuilder}.
11+
*/
912
@Module
1013
public interface BarrageFactoryBuilderModule {
1114

15+
/**
16+
* Equivalent to {@code DeephavenBarrageRoot.of().factoryBuilder()}.
17+
*
18+
* @return the barrage session factory builder
19+
* @see DeephavenBarrageRoot
20+
*/
1221
@Provides
1322
static BarrageSessionFactoryBuilder providesFactoryBuilder() {
14-
return DaggerDeephavenBarrageRoot.create().factoryBuilder();
23+
return DeephavenBarrageRoot.of().factoryBuilder();
1524
}
1625
}

java-client/barrage-dagger/src/main/java/io/deephaven/client/impl/BarrageSessionModule.java

+7
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,15 @@
88
import io.grpc.ManagedChannel;
99
import org.apache.arrow.memory.BufferAllocator;
1010

11+
/**
12+
* Provides {@link BarrageSession}.
13+
*/
1114
@Module
1215
public class BarrageSessionModule {
16+
17+
/**
18+
* Delegates to {@link BarrageSession#of(SessionImpl, BufferAllocator, ManagedChannel)}.
19+
*/
1320
@Provides
1421
public static BarrageSession newDeephavenClientSession(
1522
SessionImpl session, BufferAllocator allocator, ManagedChannel managedChannel) {

java-client/barrage-dagger/src/main/java/io/deephaven/client/impl/BarrageSubcomponent.java

+11
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,22 @@
1414
import javax.inject.Named;
1515
import java.util.concurrent.ScheduledExecutorService;
1616

17+
/**
18+
* The barrage subcomponent.
19+
*
20+
* @see SessionImplModule
21+
* @see FlightSessionModule
22+
* @see BarrageSessionModule
23+
*/
1724
@Subcomponent(modules = {SessionImplModule.class, FlightSessionModule.class, BarrageSessionModule.class})
1825
public interface BarrageSubcomponent extends BarrageSessionFactory {
1926

27+
@Override
2028
BarrageSession newBarrageSession();
2129

30+
@Override
31+
ManagedChannel managedChannel();
32+
2233
@Module(subcomponents = {BarrageSubcomponent.class})
2334
interface DeephavenClientSubcomponentModule {
2435

java-client/barrage-dagger/src/main/java/io/deephaven/client/impl/DeephavenBarrageRoot.java

+14
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,22 @@
77
import io.deephaven.client.impl.BarrageSubcomponent.Builder;
88
import io.deephaven.client.impl.BarrageSubcomponent.DeephavenClientSubcomponentModule;
99

10+
/**
11+
* Component for creating {@link BarrageSubcomponent}.
12+
*
13+
* @see DeephavenClientSubcomponentModule
14+
*/
1015
@Component(modules = DeephavenClientSubcomponentModule.class)
1116
public interface DeephavenBarrageRoot {
1217

18+
/**
19+
* Equivalent to {@code DaggerDeephavenBarrageRoot.create()}.
20+
*
21+
* @return the barrage root
22+
*/
23+
static DeephavenBarrageRoot of() {
24+
return DaggerDeephavenBarrageRoot.create();
25+
}
26+
1327
Builder factoryBuilder();
1428
}

java-client/barrage-examples/src/main/java/io/deephaven/client/examples/BarrageClientExampleBase.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import io.deephaven.client.impl.BarrageSession;
77
import io.deephaven.client.impl.BarrageSessionFactory;
88
import io.deephaven.client.impl.BarrageSubcomponent.Builder;
9-
import io.deephaven.client.impl.DaggerDeephavenBarrageRoot;
9+
import io.deephaven.client.impl.DeephavenBarrageRoot;
1010
import io.deephaven.engine.context.ExecutionContext;
1111
import io.deephaven.engine.updategraph.impl.PeriodicUpdateGraph;
1212
import io.deephaven.util.SafeCloseable;
@@ -55,7 +55,8 @@ public final Void call() throws Exception {
5555
.setUpdateGraph(updateGraph)
5656
.build();
5757

58-
final Builder builder = DaggerDeephavenBarrageRoot.create().factoryBuilder()
58+
final Builder builder = DeephavenBarrageRoot.of()
59+
.factoryBuilder()
5960
.managedChannel(managedChannel)
6061
.scheduler(scheduler)
6162
.allocator(bufferAllocator);

java-client/barrage/src/main/java/io/deephaven/client/impl/BarrageSession.java

+11-3
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,30 @@
1616

1717
public class BarrageSession extends FlightSession implements BarrageSubscription.Factory, BarrageSnapshot.Factory {
1818

19+
/**
20+
* Creates a barrage session. Closing the barrage session does <b>not</b> close {@code channel}.
21+
*
22+
* @param session the session
23+
* @param incomingAllocator the incoming allocator
24+
* @param channel the managed channel
25+
* @return the barrage session
26+
*/
1927
public static BarrageSession of(
2028
SessionImpl session, BufferAllocator incomingAllocator, ManagedChannel channel) {
2129
final FlightClient client = FlightGrpcUtilsExtension.createFlightClientWithSharedChannel(
2230
incomingAllocator, channel, Collections.singletonList(new SessionMiddleware(session)));
23-
return new BarrageSession(session, client, channel);
31+
return new BarrageSession(session, client);
2432
}
2533

2634
public static BarrageSession create(
2735
SessionImpl session, BufferAllocator incomingAllocator, ManagedChannel channel) {
2836
final FlightClient client = FlightGrpcUtilsExtension.createFlightClientWithSharedChannel(
2937
incomingAllocator, channel, Collections.singletonList(new SessionMiddleware(session)));
30-
return new BarrageSession(session, client, channel);
38+
return new BarrageSession(session, client);
3139
}
3240

3341
protected BarrageSession(
34-
final SessionImpl session, final FlightClient client, final ManagedChannel channel) {
42+
final SessionImpl session, final FlightClient client) {
3543
super(session, client);
3644
}
3745

java-client/barrage/src/main/java/io/deephaven/client/impl/BarrageSessionFactory.java

+16
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@
33
//
44
package io.deephaven.client.impl;
55

6+
import io.grpc.ManagedChannel;
7+
68
public interface BarrageSessionFactory {
9+
10+
/**
11+
* Creates a new {@link BarrageSession}. Closing the session does <b>not</b> close the {@link #managedChannel()}.
12+
*
13+
* @return the new barrage session
14+
*/
715
BarrageSession newBarrageSession();
16+
17+
/**
18+
* The {@link ManagedChannel} associated with {@code this} factory. Use {@link ManagedChannel#shutdown()} when
19+
* {@code this} factory and sessions are no longer needed.
20+
*
21+
* @return the managed channel
22+
*/
23+
ManagedChannel managedChannel();
824
}

java-client/flight-dagger/src/main/java/io/deephaven/client/impl/DeephavenFlightRoot.java

+14
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,22 @@
77
import io.deephaven.client.impl.FlightSubcomponent.Builder;
88
import io.deephaven.client.impl.FlightSubcomponent.FlightSubcomponentModule;
99

10+
/**
11+
* Component for creating {@link FlightSubcomponent}.
12+
*
13+
* @see FlightSubcomponentModule
14+
*/
1015
@Component(modules = FlightSubcomponentModule.class)
1116
public interface DeephavenFlightRoot {
1217

18+
/**
19+
* Equivalent to {@code DaggerDeephavenFlightRoot.create()}.
20+
*
21+
* @return the flight root
22+
*/
23+
static DeephavenFlightRoot of() {
24+
return DaggerDeephavenFlightRoot.create();
25+
}
26+
1327
Builder factoryBuilder();
1428
}

java-client/flight-dagger/src/main/java/io/deephaven/client/impl/FlightSessionModule.java

+6
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@
88
import io.grpc.ManagedChannel;
99
import org.apache.arrow.memory.BufferAllocator;
1010

11+
/**
12+
* Provides {@link FlightSession}.
13+
*/
1114
@Module
1215
public class FlightSessionModule {
1316

17+
/**
18+
* Delegates to {@link FlightSession#of(SessionImpl, BufferAllocator, ManagedChannel)}.
19+
*/
1420
@Provides
1521
public static FlightSession newFlightSession(SessionImpl session, BufferAllocator allocator,
1622
ManagedChannel managedChannel) {

java-client/flight-dagger/src/main/java/io/deephaven/client/impl/FlightSubcomponent.java

+10
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,21 @@
1414
import javax.inject.Named;
1515
import java.util.concurrent.ScheduledExecutorService;
1616

17+
/**
18+
* The flight subcomponent.
19+
*
20+
* @see SessionImplModule
21+
* @see FlightSessionModule
22+
*/
1723
@Subcomponent(modules = {SessionImplModule.class, FlightSessionModule.class})
1824
public interface FlightSubcomponent extends FlightSessionFactory {
1925

26+
@Override
2027
FlightSession newFlightSession();
2128

29+
@Override
30+
ManagedChannel managedChannel();
31+
2232
@Module(subcomponents = {FlightSubcomponent.class})
2333
interface FlightSubcomponentModule {
2434

java-client/flight-dagger/src/test/java/io/deephaven/client/DeephavenFlightSessionTestBase.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//
44
package io.deephaven.client;
55

6-
import io.deephaven.client.impl.DaggerDeephavenFlightRoot;
6+
import io.deephaven.client.impl.DeephavenFlightRoot;
77
import io.deephaven.client.impl.FlightSession;
88
import io.deephaven.server.runner.DeephavenApiServerTestBase;
99
import io.grpc.ManagedChannel;
@@ -30,8 +30,13 @@ public void setUp() throws Exception {
3030
register(channel);
3131
sessionScheduler = Executors.newScheduledThreadPool(2);
3232
bufferAllocator = new RootAllocator();
33-
flightSession = DaggerDeephavenFlightRoot.create().factoryBuilder().allocator(bufferAllocator)
34-
.managedChannel(channel).scheduler(sessionScheduler).build().newFlightSession();
33+
flightSession = DeephavenFlightRoot.of()
34+
.factoryBuilder()
35+
.allocator(bufferAllocator)
36+
.managedChannel(channel)
37+
.scheduler(sessionScheduler)
38+
.build()
39+
.newFlightSession();
3540
}
3641

3742
@Override

java-client/flight-examples/src/main/java/io/deephaven/client/examples/DoPutSpray.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//
44
package io.deephaven.client.examples;
55

6-
import io.deephaven.client.impl.DaggerDeephavenFlightRoot;
6+
import io.deephaven.client.impl.DeephavenFlightRoot;
77
import io.deephaven.client.impl.FlightSession;
88
import io.deephaven.client.impl.TableHandle;
99
import io.deephaven.qst.table.TicketTable;
@@ -72,7 +72,8 @@ private static void close(FlightSession session) throws InterruptedException, Ex
7272

7373
private FlightSession session(BufferAllocator bufferAllocator, ScheduledExecutorService scheduler,
7474
ManagedChannel sourceChannel) {
75-
return DaggerDeephavenFlightRoot.create().factoryBuilder()
75+
return DeephavenFlightRoot.of()
76+
.factoryBuilder()
7677
.managedChannel(sourceChannel)
7778
.scheduler(scheduler)
7879
.allocator(bufferAllocator)

java-client/flight-examples/src/main/java/io/deephaven/client/examples/FlightExampleBase.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//
44
package io.deephaven.client.examples;
55

6-
import io.deephaven.client.impl.DaggerDeephavenFlightRoot;
6+
import io.deephaven.client.impl.DeephavenFlightRoot;
77
import io.deephaven.client.impl.FlightSession;
88
import io.deephaven.client.impl.FlightSessionFactory;
99
import io.deephaven.client.impl.FlightSubcomponent.Builder;
@@ -36,7 +36,8 @@ public final Void call() throws Exception {
3636
Runtime.getRuntime()
3737
.addShutdownHook(new Thread(() -> onShutdown(scheduler, managedChannel)));
3838

39-
final Builder builder = DaggerDeephavenFlightRoot.create().factoryBuilder()
39+
final Builder builder = DeephavenFlightRoot.of()
40+
.factoryBuilder()
4041
.managedChannel(managedChannel)
4142
.scheduler(scheduler)
4243
.allocator(bufferAllocator);

java-client/flight/src/main/java/io/deephaven/client/impl/FlightSession.java

+8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818

1919
public class FlightSession implements AutoCloseable {
2020

21+
/**
22+
* Creates a flight session. Closing the flight session does <b>not</b> close {@code channel}.
23+
*
24+
* @param session the session
25+
* @param incomingAllocator the incoming allocator
26+
* @param channel the managed channel
27+
* @return the flight session
28+
*/
2129
public static FlightSession of(SessionImpl session, BufferAllocator incomingAllocator,
2230
ManagedChannel channel) {
2331
// Note: this pattern of FlightClient owning the ManagedChannel does not mesh well with the idea that some

java-client/flight/src/main/java/io/deephaven/client/impl/FlightSessionFactory.java

+15
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@
33
//
44
package io.deephaven.client.impl;
55

6+
import io.grpc.ManagedChannel;
7+
68
public interface FlightSessionFactory {
9+
/**
10+
* Creates a new {@link FlightSession}. Closing the session does <b>not</b> close the {@link #managedChannel()}.
11+
*
12+
* @return the new flight session
13+
*/
714
FlightSession newFlightSession();
15+
16+
/**
17+
* The {@link ManagedChannel} associated with {@code this} factory. Use {@link ManagedChannel#shutdown()} when
18+
* {@code this} factory and sessions are no longer needed.
19+
*
20+
* @return the managed channel
21+
*/
22+
ManagedChannel managedChannel();
823
}

java-client/session-dagger/src/main/java/io/deephaven/client/DeephavenSessionRoot.java

+14
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,22 @@
77
import io.deephaven.client.SessionSubcomponent.Builder;
88
import io.deephaven.client.SessionSubcomponent.SessionFactorySubcomponentModule;
99

10+
/**
11+
* Component for creating {@link SessionSubcomponent}.
12+
*
13+
* @see SessionFactorySubcomponentModule
14+
*/
1015
@Component(modules = SessionFactorySubcomponentModule.class)
1116
public interface DeephavenSessionRoot {
1217

18+
/**
19+
* Equivalent to {@code DaggerDeephavenSessionRoot.create()}.
20+
*
21+
* @return the session root
22+
*/
23+
static DeephavenSessionRoot of() {
24+
return DaggerDeephavenSessionRoot.create();
25+
}
26+
1327
Builder factoryBuilder();
1428
}

java-client/session-dagger/src/main/java/io/deephaven/client/SessionImplModule.java

+21-9
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import dagger.Provides;
99
import io.deephaven.client.impl.SessionImpl;
1010
import io.deephaven.client.impl.SessionImplConfig;
11-
import io.deephaven.client.impl.SessionImplConfig.Builder;
1211
import io.deephaven.proto.DeephavenChannel;
1312
import io.deephaven.proto.DeephavenChannelImpl;
1413
import io.grpc.Channel;
@@ -18,6 +17,9 @@
1817
import javax.inject.Named;
1918
import java.util.concurrent.ScheduledExecutorService;
2019

20+
/**
21+
* Provides {@link Channel}, {@link DeephavenChannel}, {@link SessionImplConfig}, and {@link SessionImpl}.
22+
*/
2123
@Module
2224
public interface SessionImplModule {
2325

@@ -27,19 +29,29 @@ public interface SessionImplModule {
2729
@Binds
2830
DeephavenChannel bindsDeephavenChannelImpl(DeephavenChannelImpl deephavenChannelImpl);
2931

32+
/**
33+
* Delegates to {@link SessionImplConfig#of(DeephavenChannel, ScheduledExecutorService, String)}.
34+
*/
3035
@Provides
31-
static SessionImpl session(DeephavenChannel channel, ScheduledExecutorService scheduler,
36+
static SessionImplConfig providesSessionImplConfig(
37+
DeephavenChannel channel,
38+
ScheduledExecutorService scheduler,
3239
@Nullable @Named("authenticationTypeAndValue") String authenticationTypeAndValue) {
33-
final Builder builder = SessionImplConfig.builder()
34-
.executor(scheduler)
35-
.channel(channel);
36-
if (authenticationTypeAndValue != null) {
37-
builder.authenticationTypeAndValue(authenticationTypeAndValue);
38-
}
39-
final SessionImplConfig config = builder.build();
40+
return SessionImplConfig.of(channel, scheduler, authenticationTypeAndValue);
41+
}
42+
43+
/**
44+
* Creates a session. Equivalent to {@link SessionImplConfig#createSession()}.
45+
*
46+
* @param config the config
47+
* @return the session
48+
*/
49+
@Provides
50+
static SessionImpl session(SessionImplConfig config) {
4051
try {
4152
return config.createSession();
4253
} catch (InterruptedException e) {
54+
Thread.currentThread().interrupt();
4355
throw new RuntimeException(e);
4456
}
4557
}

0 commit comments

Comments
 (0)