public ByteStreamClientImpl(String scope, Controller controller, ConnectionFactory connectionFactory) { this.scope = Preconditions.checkNotNull(scope); this.controller = Preconditions.checkNotNull(controller); this.connectionFactory = Preconditions.checkNotNull(connectionFactory); this.inputStreamFactory = new SegmentInputStreamFactoryImpl(controller, connectionFactory); this.outputStreamFactory = new SegmentOutputStreamFactoryImpl(controller, connectionFactory); this.metaStreamFactory = new SegmentMetadataClientFactoryImpl(controller, connectionFactory); }
/** * Creates a new instance of the ClientFactory class. * Note: ConnectionFactory and Controller is closed when {@link ClientFactoryImpl#close()} is invoked. * * @param scope The scope string. * @param controller The reference to Controller. * @param connectionFactory The reference to Connection Factory impl. */ @VisibleForTesting public ClientFactoryImpl(String scope, Controller controller, ConnectionFactory connectionFactory) { this(scope, controller, connectionFactory, new SegmentInputStreamFactoryImpl(controller, connectionFactory), new SegmentOutputStreamFactoryImpl(controller, connectionFactory), new ConditionalOutputStreamFactoryImpl(controller, connectionFactory), new SegmentMetadataClientFactoryImpl(controller, connectionFactory)); }
/** * Creates a new instance of ClientFactory class. * Note: Controller is closed when {@link ClientFactoryImpl#close()} is invoked. * * @param scope The scope string. * @param controller The reference to Controller. */ public ClientFactoryImpl(String scope, Controller controller) { Preconditions.checkNotNull(scope); Preconditions.checkNotNull(controller); this.scope = scope; this.controller = controller; this.connectionFactory = new ConnectionFactoryImpl(ClientConfig.builder().build()); this.inFactory = new SegmentInputStreamFactoryImpl(controller, connectionFactory); this.outFactory = new SegmentOutputStreamFactoryImpl(controller, connectionFactory); this.condFactory = new ConditionalOutputStreamFactoryImpl(controller, connectionFactory); this.metaFactory = new SegmentMetadataClientFactoryImpl(controller, connectionFactory); }
controller.createStream(scope, stream, StreamConfiguration.builder().build()); SegmentOutputStreamFactoryImpl segmentproducerClient = new SegmentOutputStreamFactoryImpl(controller, clientCF);
controller.createStream(scope, stream, StreamConfiguration.builder().build()); SegmentOutputStreamFactoryImpl segmentClient = new SegmentOutputStreamFactoryImpl(controller, clientCF);
@Test public void appendThroughSegmentClient() throws Exception { String endpoint = "localhost"; int port = TestUtils.getAvailableListenPort(); String testString = "Hello world\n"; String scope = "scope"; String stream = "stream"; StreamSegmentStore store = this.serviceBuilder.createStreamSegmentService(); TableStore tableStore = serviceBuilder.createTableStoreService(); @Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store, tableStore); server.startListening(); @Cleanup ConnectionFactory clientCF = new ConnectionFactoryImpl(ClientConfig.builder().build()); Controller controller = new MockController(endpoint, port, clientCF); controller.createScope(scope); controller.createStream(scope, stream, StreamConfiguration.builder().build()); SegmentOutputStreamFactoryImpl segmentClient = new SegmentOutputStreamFactoryImpl(controller, clientCF); Segment segment = Futures.getAndHandleExceptions(controller.getCurrentSegments(scope, stream), RuntimeException::new).getSegments().iterator().next(); @Cleanup SegmentOutputStream out = segmentClient.createOutputStreamForSegment(segment, segmentSealedCallback, EventWriterConfig.builder().build(), ""); CompletableFuture<Void> ack = new CompletableFuture<>(); out.write(PendingEvent.withHeader(null, ByteBuffer.wrap(testString.getBytes()), ack)); ack.get(5, TimeUnit.SECONDS); }