diff --git a/build.gradle b/build.gradle index b73a2e226..2150baf29 100644 --- a/build.gradle +++ b/build.gradle @@ -32,7 +32,6 @@ subprojects { ext['logback.version'] = '1.2.3' ext['findbugs.version'] = '3.0.2' ext['netty.version'] = '4.1.29.Final' - ext['aeron.version'] = '1.11.2' ext['hdrhistogram.version'] = '2.1.10' ext['jctool.version'] = '2.1.2' ext['mockito.version'] = '2.23.0' @@ -52,7 +51,6 @@ subprojects { dependency "ch.qos.logback:logback-classic:${ext['logback.version']}" dependency "com.google.code.findbugs:jsr305:${ext['findbugs.version']}" dependency "io.netty:netty-buffer:${ext['netty.version']}" - dependency "io.aeron:aeron-all:${ext['aeron.version']}" dependency "io.micrometer:micrometer-core:${ext['micrometer.version']}" dependency "org.assertj:assertj-core:${ext['assertj.version']}" dependency "org.hdrhistogram:HdrHistogram:${ext['hdrhistogram.version']}" diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index ed88a042a..f6b961fd5 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9a4163a4f..e0b3fb8d7 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/rsocket-transport-aeron/build.gradle b/rsocket-transport-aeron/build.gradle deleted file mode 100644 index cf983a9de..000000000 --- a/rsocket-transport-aeron/build.gradle +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -plugins { - id 'java-library' - id 'maven-publish' - id 'com.jfrog.artifactory' - id 'com.jfrog.bintray' -} - -dependencies { - api project(':rsocket-core') - api 'io.aeron:aeron-all' - - implementation 'org.slf4j:slf4j-api' - - testImplementation project(':rsocket-test') - testImplementation 'org.junit.jupiter:junit-jupiter-api' - - // TODO: Remove after JUnit5 migration - testCompileOnly 'junit:junit' - testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' -} - -description = 'Aeron RSocket transport implementation' diff --git a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/AeronDuplexConnection.java b/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/AeronDuplexConnection.java deleted file mode 100644 index 644f8e6ab..000000000 --- a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/AeronDuplexConnection.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.rsocket.aeron; - -import io.netty.buffer.Unpooled; -import io.rsocket.DuplexConnection; -import io.rsocket.Frame; -import io.rsocket.aeron.internal.reactivestreams.AeronChannel; -import org.agrona.concurrent.UnsafeBuffer; -import org.reactivestreams.Publisher; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; -import reactor.core.publisher.MonoProcessor; - -/** - * Implementation of {@link DuplexConnection} over Aeron using an {@link - * io.rsocket.aeron.internal.reactivestreams.AeronChannel} - */ -public class AeronDuplexConnection implements DuplexConnection { - private final String name; - private final AeronChannel channel; - private final MonoProcessor onClose; - - public AeronDuplexConnection(String name, AeronChannel channel) { - this.name = name; - this.channel = channel; - this.onClose = MonoProcessor.create(); - } - - @Override - public Mono send(Publisher frame) { - Flux buffers = - Flux.from(frame).map(f -> new UnsafeBuffer(f.content().nioBuffer())); - - return channel.send(buffers); - } - - @Override - public Flux receive() { - return channel - .receive() - .map(b -> Frame.from(Unpooled.wrappedBuffer(b.byteBuffer()))) - .doOnError(Throwable::printStackTrace); - } - - @Override - public void dispose() { - try { - channel.dispose(); - onClose.onComplete(); - } catch (Exception e) { - onClose.onError(e); - } - } - - @Override - public boolean isDisposed() { - return channel.isDisposed(); - } - - @Override - public Mono onClose() { - return onClose; - } - - @Override - public String toString() { - return "AeronDuplexConnection{" - + "name='" - + name - + '\'' - + ", channel=" - + channel - + ", onClose=" - + onClose - + '}'; - } -} diff --git a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/client/AeronClientTransport.java b/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/client/AeronClientTransport.java deleted file mode 100644 index 970887f98..000000000 --- a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/client/AeronClientTransport.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.rsocket.aeron.client; - -import io.rsocket.DuplexConnection; -import io.rsocket.aeron.AeronDuplexConnection; -import io.rsocket.aeron.internal.reactivestreams.AeronChannel; -import io.rsocket.aeron.internal.reactivestreams.AeronClientChannelConnector; -import io.rsocket.transport.ClientTransport; -import java.util.Objects; -import org.reactivestreams.Publisher; -import reactor.core.publisher.Mono; - -/** {@link ClientTransport} implementation that uses Aeron as a transport */ -public class AeronClientTransport implements ClientTransport { - private final AeronClientChannelConnector connector; - private final AeronClientChannelConnector.AeronClientConfig config; - - public AeronClientTransport( - AeronClientChannelConnector connector, AeronClientChannelConnector.AeronClientConfig config) { - Objects.requireNonNull(config); - Objects.requireNonNull(connector); - this.connector = connector; - this.config = config; - } - - @Override - public Mono connect() { - Publisher channelPublisher = connector.apply(config); - - return Mono.from(channelPublisher) - .map(aeronChannel -> new AeronDuplexConnection("client", aeronChannel)); - } -} diff --git a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/AeronWrapper.java b/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/AeronWrapper.java deleted file mode 100644 index 9434b322c..000000000 --- a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/AeronWrapper.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.rsocket.aeron.internal; - -import io.aeron.Aeron; -import io.aeron.Image; -import io.aeron.Publication; -import io.aeron.Subscription; -import java.util.function.Function; - -/** */ -public interface AeronWrapper { - Aeron getAeron(); - - void availableImageHandler(Function handler); - - void unavailableImageHandlers(Function handler); - - default Subscription addSubscription(String channel, int streamId) { - return getAeron().addSubscription(channel, streamId); - } - - default Publication addPublication(String channel, int streamId) { - return getAeron().addPublication(channel, streamId); - } - - default void close() { - getAeron().close(); - } -} diff --git a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/Constants.java b/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/Constants.java deleted file mode 100644 index 70ca1ebd4..000000000 --- a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/Constants.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.rsocket.aeron.internal; - -import java.util.concurrent.TimeUnit; -import org.agrona.concurrent.BackoffIdleStrategy; -import org.agrona.concurrent.IdleStrategy; -import org.agrona.concurrent.NoOpIdleStrategy; -import org.agrona.concurrent.SleepingIdleStrategy; - -public final class Constants { - - public static final int SERVER_STREAM_ID = 0; - public static final int CLIENT_STREAM_ID = 1; - public static final int SERVER_MANAGEMENT_STREAM_ID = 10; - public static final int CLIENT_MANAGEMENT_STREAM_ID = 11; - public static final IdleStrategy EVENT_LOOP_IDLE_STRATEGY; - public static final int AERON_MTU_SIZE = Integer.getInteger("aeron.mtu.length", 4096); - - static { - String idlStrategy = System.getProperty("idleStrategy"); - - if (NoOpIdleStrategy.class.getName().equalsIgnoreCase(idlStrategy)) { - EVENT_LOOP_IDLE_STRATEGY = new NoOpIdleStrategy(); - } else if (SleepingIdleStrategy.class.getName().equalsIgnoreCase(idlStrategy)) { - EVENT_LOOP_IDLE_STRATEGY = new SleepingIdleStrategy(TimeUnit.MILLISECONDS.toNanos(10)); - } else { - EVENT_LOOP_IDLE_STRATEGY = new BackoffIdleStrategy(1, 10, 1_000, 100_000); - } - } - - private Constants() {} -} diff --git a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/DefaultAeronWrapper.java b/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/DefaultAeronWrapper.java deleted file mode 100644 index a6d3b7a6b..000000000 --- a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/DefaultAeronWrapper.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.rsocket.aeron.internal; - -import io.aeron.Aeron; -import io.aeron.Image; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; -import java.util.concurrent.CopyOnWriteArraySet; -import java.util.function.Function; - -/** */ -public class DefaultAeronWrapper implements AeronWrapper { - private Set> availableImageHandlers; - private Set> unavailableImageHandlers; - - private Aeron aeron; - - public DefaultAeronWrapper() { - this.availableImageHandlers = new CopyOnWriteArraySet<>(); - this.unavailableImageHandlers = new CopyOnWriteArraySet<>(); - - Aeron.Context ctx = new Aeron.Context(); - - ctx.availableImageHandler(this::availableImageHandler); - ctx.unavailableImageHandler(this::unavailableImageHandler); - - this.aeron = Aeron.connect(ctx); - } - - public Aeron getAeron() { - return aeron; - } - - public void availableImageHandler(Function handler) { - availableImageHandlers.add(handler); - } - - public void unavailableImageHandlers(Function handler) { - unavailableImageHandlers.add(handler); - } - - private void availableImageHandler(Image image) { - Iterator> iterator = availableImageHandlers.iterator(); - - Set> itemsToRemove = new HashSet<>(); - while (iterator.hasNext()) { - Function handler = iterator.next(); - if (handler.apply(image)) { - itemsToRemove.add(handler); - } - } - - availableImageHandlers.removeAll(itemsToRemove); - } - - private void unavailableImageHandler(Image image) { - unavailableImageHandlers.removeIf(handler -> handler.apply(image)); - } -} diff --git a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/EventLoop.java b/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/EventLoop.java deleted file mode 100644 index df5f64718..000000000 --- a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/EventLoop.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.rsocket.aeron.internal; - -import java.util.function.IntSupplier; - -/** Interface for an EventLoop used by Aeron */ -public interface EventLoop { - /** - * Executes an IntSupplier that returns a number greater than 0 if it wants the the event loop to - * keep processing items, and zero its okay for the eventloop to execute an idle strategy - * - * @param r signal for roughly how many items could be processed. - * @return whether items could be processed - */ - boolean execute(IntSupplier r); -} diff --git a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/NotConnectedException.java b/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/NotConnectedException.java deleted file mode 100644 index f97413b15..000000000 --- a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/NotConnectedException.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.rsocket.aeron.internal; - -public class NotConnectedException extends RuntimeException { - - private static final long serialVersionUID = -5521573868855763403L; - - public NotConnectedException() { - super(); - } - - public NotConnectedException(String message) { - super(message); - } -} diff --git a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/SingleThreadedEventLoop.java b/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/SingleThreadedEventLoop.java deleted file mode 100644 index 24a02cb44..000000000 --- a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/SingleThreadedEventLoop.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.rsocket.aeron.internal; - -import java.util.concurrent.locks.LockSupport; -import java.util.function.IntSupplier; -import org.agrona.concurrent.IdleStrategy; -import org.agrona.concurrent.OneToOneConcurrentArrayQueue; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** */ -public class SingleThreadedEventLoop implements EventLoop { - private static final Logger logger = LoggerFactory.getLogger(SingleThreadedEventLoop.class); - private final String name; - private final Thread thread; - private final OneToOneConcurrentArrayQueue events = - new OneToOneConcurrentArrayQueue<>(32768); - - public SingleThreadedEventLoop(String name) { - this.name = name; - logger.info("Starting event loop named => {}", name); - - thread = new Thread(new SingleThreadedEventLoopRunnable()); - thread.setDaemon(true); - thread.setName("aeron-single-threaded-event-loop-" + name); - thread.start(); - } - - @Override - public boolean execute(IntSupplier r) { - boolean offer; - - if (thread == Thread.currentThread()) { - offer = events.offer(r); - } else { - synchronized (this) { - offer = events.offer(r); - } - LockSupport.unpark(thread); - } - - return offer; - } - - private int drain() { - int count = 0; - while (!events.isEmpty()) { - IntSupplier poll = events.poll(); - if (poll != null) { - count += poll.getAsInt(); - } - } - - return count; - } - - private class SingleThreadedEventLoopRunnable implements Runnable { - final IdleStrategy idleStrategy = Constants.EVENT_LOOP_IDLE_STRATEGY; - - @Override - public void run() { - while (true) { - try { - int count = drain(); - // if (count > 100) { - // System.out.println(name + " drained..." + count); - // } - idleStrategy.idle(count); - } catch (Throwable t) { - System.err.println("Something bad happened - an error made it to the event loop"); - t.printStackTrace(); - } - } - } - } - - @Override - public String toString() { - return "SingleThreadedEventLoop{" + "name='" + name + '\'' + '}'; - } -} diff --git a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/TimedOutException.java b/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/TimedOutException.java deleted file mode 100644 index e77eecdfd..000000000 --- a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/TimedOutException.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.rsocket.aeron.internal; - -public class TimedOutException extends RuntimeException { - - private static final long serialVersionUID = 6252022225519863073L; -} diff --git a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/AeronChannel.java b/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/AeronChannel.java deleted file mode 100644 index 5275f0c92..000000000 --- a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/AeronChannel.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.rsocket.aeron.internal.reactivestreams; - -import io.aeron.Publication; -import io.aeron.Subscription; -import io.rsocket.aeron.internal.EventLoop; -import java.util.Objects; -import org.agrona.DirectBuffer; -import reactor.core.Disposable; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - -/** */ -public class AeronChannel implements ReactiveStreamsRemote.Channel, Disposable { - private final String name; - private final Publication destination; - private final Subscription source; - private final AeronOutPublisher outPublisher; - private final EventLoop eventLoop; - - /** - * Creates on end of a bi-directional channel - * - * @param name name of the channel - * @param destination {@code Publication} to send data to - * @param source Aeron {@code Subscription} to listen to data on - * @param eventLoop {@link EventLoop} used to poll data on - * @param sessionId sessionId between the {@code Publication} and the remote {@code Subscription} - */ - public AeronChannel( - String name, - Publication destination, - Subscription source, - EventLoop eventLoop, - int sessionId) { - this.destination = destination; - this.source = source; - this.name = name; - this.eventLoop = eventLoop; - this.outPublisher = new AeronOutPublisher(name, sessionId, source, eventLoop); - } - - /** - * Subscribes to a stream of DirectBuffers and sends the to an Aeron Publisher - * - * @param in the publisher of buffers. - * @return Mono the completes when all publishers have been sent. - */ - public Mono send(Flux in) { - AeronInSubscriber inSubscriber = new AeronInSubscriber(name, destination); - Objects.requireNonNull(in, "in must not be null"); - return Mono.create( - sink -> in.doOnComplete(sink::success).doOnError(sink::error).subscribe(inSubscriber)); - } - - /** - * Returns ReactiveStreamsRemote.Out of DirectBuffer that can only be subscribed to once per - * channel - * - * @return ReactiveStreamsRemote.Out of DirectBuffer - */ - public Flux receive() { - return outPublisher; - } - - @Override - public void dispose() { - destination.close(); - source.close(); - } - - @Override - public boolean isDisposed() { - return destination.isClosed() && source.isClosed(); - } - - @Override - public String toString() { - return "AeronChannel{" + "name='" + name + '\'' + '}'; - } -} diff --git a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/AeronChannelServer.java b/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/AeronChannelServer.java deleted file mode 100644 index 3afe64a13..000000000 --- a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/AeronChannelServer.java +++ /dev/null @@ -1,284 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.rsocket.aeron.internal.reactivestreams; - -import io.aeron.FragmentAssembler; -import io.aeron.Publication; -import io.aeron.Subscription; -import io.aeron.logbuffer.FragmentHandler; -import io.aeron.logbuffer.Header; -import io.rsocket.Closeable; -import io.rsocket.aeron.internal.AeronWrapper; -import io.rsocket.aeron.internal.Constants; -import io.rsocket.aeron.internal.EventLoop; -import io.rsocket.aeron.internal.NotConnectedException; -import io.rsocket.aeron.internal.reactivestreams.messages.AckConnectEncoder; -import io.rsocket.aeron.internal.reactivestreams.messages.ConnectDecoder; -import io.rsocket.aeron.internal.reactivestreams.messages.MessageHeaderDecoder; -import io.rsocket.aeron.internal.reactivestreams.messages.MessageHeaderEncoder; -import java.net.SocketAddress; -import java.nio.ByteBuffer; -import java.time.Duration; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; -import org.agrona.DirectBuffer; -import org.agrona.concurrent.UnsafeBuffer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import reactor.core.publisher.Mono; -import reactor.core.publisher.MonoProcessor; - -/** - * Implementation of {@link - * io.rsocket.aeron.internal.reactivestreams.ReactiveStreamsRemote.ChannelServer} that manages - * {@link AeronChannel}s. - */ -public class AeronChannelServer - extends ReactiveStreamsRemote.ChannelServer { - private static final Logger logger = LoggerFactory.getLogger(AeronChannelServer.class); - private final AeronWrapper aeronWrapper; - private final AeronSocketAddress managementSubscriptionSocket; - private final AtomicBoolean started = new AtomicBoolean(false); - private final ConcurrentHashMap serverSubscriptions; - private volatile boolean running = true; - private final EventLoop eventLoop; - private Subscription managementSubscription; - private AeronChannelStartedServer startServer; - - private AeronChannelServer( - AeronChannelConsumer channelConsumer, - AeronWrapper aeronWrapper, - AeronSocketAddress managementSubscriptionSocket, - EventLoop eventLoop) { - super(channelConsumer); - this.aeronWrapper = aeronWrapper; - this.managementSubscriptionSocket = managementSubscriptionSocket; - this.eventLoop = eventLoop; - this.serverSubscriptions = new ConcurrentHashMap<>(); - } - - public static AeronChannelServer create( - AeronChannelConsumer channelConsumer, - AeronWrapper aeronWrapper, - AeronSocketAddress managementSubscriptionSocket, - EventLoop eventLoop) { - return new AeronChannelServer( - channelConsumer, aeronWrapper, managementSubscriptionSocket, eventLoop); - } - - @Override - public AeronChannelStartedServer start() { - if (!started.compareAndSet(false, true)) { - throw new IllegalStateException("server already started"); - } - - logger.debug( - "management server starting on {}, stream id {}", - managementSubscriptionSocket.getChannel(), - Constants.SERVER_MANAGEMENT_STREAM_ID); - - this.managementSubscription = - aeronWrapper.addSubscription( - managementSubscriptionSocket.getChannel(), Constants.SERVER_MANAGEMENT_STREAM_ID); - - this.startServer = new AeronChannelStartedServer(); - - poll(); - - return startServer; - } - - private final FragmentAssembler fragmentAssembler = - new FragmentAssembler( - new FragmentHandler() { - private final MessageHeaderDecoder messageHeaderDecoder = new MessageHeaderDecoder(); - private final ConnectDecoder connectDecoder = new ConnectDecoder(); - private final MessageHeaderEncoder messageHeaderEncoder = new MessageHeaderEncoder(); - private final AckConnectEncoder ackConnectEncoder = new AckConnectEncoder(); - - @Override - public void onFragment(DirectBuffer buffer, int offset, int length, Header header) { - messageHeaderDecoder.wrap(buffer, offset); - - // Do not change the order or remove fields - final int actingBlockLength = messageHeaderDecoder.blockLength(); - final int templateId = messageHeaderDecoder.templateId(); - final int schemaId = messageHeaderDecoder.schemaId(); - final int actingVersion = messageHeaderDecoder.version(); - - if (templateId == ConnectDecoder.TEMPLATE_ID) { - offset += messageHeaderDecoder.encodedLength(); - connectDecoder.wrap(buffer, offset, actingBlockLength, actingVersion); - - // Do not change the order or remove fields - long channelId = connectDecoder.channelId(); - String receivingChannel = connectDecoder.receivingChannel(); - int receivingStreamId = connectDecoder.receivingStreamId(); - String sendingChannel = connectDecoder.sendingChannel(); - int sendingStreamId = connectDecoder.sendingStreamId(); - int clientSessionId = connectDecoder.clientSessionId(); - String clientManagementChannel = connectDecoder.clientManagementChannel(); - - logger.debug( - "server creating a AeronChannel with channel id {} receiving on receivingChannel {}, receivingStreamId {}, sendingChannel {}, sendingStreamId {}", - channelId, - receivingChannel, - receivingStreamId, - sendingChannel, - sendingStreamId); - - // Server sends to receiving Channel - Publication destination = - aeronWrapper.addPublication(receivingChannel, receivingStreamId); - int sessionId = destination.sessionId(); - logger.debug( - "server created publication to channel {}, stream id {}, and session id {}", - receivingChannel, - receivingStreamId, - sessionId); - - // Server listens to sending channel - Subscription source = - serverSubscriptions.computeIfAbsent( - sendingChannel, - s -> aeronWrapper.addSubscription(sendingChannel, sendingStreamId)); - logger.debug( - "server created subscription to channel {}, stream id {}", - sendingChannel, - sendingStreamId); - - AeronChannel aeronChannel = - new AeronChannel("server", destination, source, eventLoop, clientSessionId); - logger.debug( - "server create AeronChannel with destination channel {}, source channel {}, and clientSessionId {}"); - - channelConsumer.accept(aeronChannel); - - Publication managementPublication = - aeronWrapper.addPublication( - clientManagementChannel, Constants.CLIENT_MANAGEMENT_STREAM_ID); - logger.debug( - "server created management publication to channel {}", clientManagementChannel); - - final ByteBuffer byteBuffer = ByteBuffer.allocateDirect(4096); - final UnsafeBuffer directBuffer = new UnsafeBuffer(byteBuffer); - int bufferOffset = 0; - - messageHeaderEncoder - .wrap(directBuffer, bufferOffset) - .blockLength(AckConnectEncoder.BLOCK_LENGTH) - .templateId(AckConnectEncoder.TEMPLATE_ID) - .schemaId(AckConnectEncoder.SCHEMA_ID) - .version(AckConnectEncoder.SCHEMA_VERSION); - - bufferOffset += messageHeaderEncoder.encodedLength(); - - ackConnectEncoder - .wrap(directBuffer, bufferOffset) - .channelId(channelId) - .serverSessionId(destination.sessionId()); - - logger.debug( - "server sending AckConnect message to channel {}", clientManagementChannel); - - long offer; - do { - offer = managementPublication.offer(directBuffer); - if (offer == Publication.CLOSED) { - throw new NotConnectedException(); - } - } while (offer < 0); - } - } - }); - - private int poll() { - int poll; - try { - poll = managementSubscription.poll(fragmentAssembler, 4096); - } finally { - if (running) { - boolean execute = eventLoop.execute(this::poll); - if (!execute) { - running = false; - throw new IllegalStateException("unable to keep polling, eventLoop rejection"); - } - } - } - - return poll; - } - - public interface AeronChannelConsumer - extends ReactiveStreamsRemote.ChannelConsumer {} - - public class AeronChannelStartedServer implements ReactiveStreamsRemote.StartedServer, Closeable { - private final MonoProcessor onClose = MonoProcessor.create(); - - public AeronWrapper getAeronWrapper() { - return aeronWrapper; - } - - public EventLoop getEventLoop() { - return eventLoop; - } - - @Override - public SocketAddress getServerAddress() { - return managementSubscriptionSocket; - } - - @Override - public int getServerPort() { - return managementSubscriptionSocket.getPort(); - } - - @Override - public void awaitShutdown(long duration, TimeUnit durationUnit) { - Duration d = Duration.ofMillis(durationUnit.toMillis(duration)); - onClose().block(d); - } - - @Override - public void awaitShutdown() { - onClose().block(); - } - - @Override - public void shutdown() { - dispose(); - } - - @Override - public void dispose() { - running = false; - managementSubscription.close(); - onClose.onComplete(); - } - - @Override - public boolean isDisposed() { - return onClose.isDisposed(); - } - - @Override - public Mono onClose() { - return onClose; - } - } -} diff --git a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/AeronClientChannelConnector.java b/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/AeronClientChannelConnector.java deleted file mode 100644 index 7272ecbfc..000000000 --- a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/AeronClientChannelConnector.java +++ /dev/null @@ -1,341 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.rsocket.aeron.internal.reactivestreams; - -import io.aeron.FragmentAssembler; -import io.aeron.Publication; -import io.aeron.Subscription; -import io.aeron.logbuffer.FragmentHandler; -import io.aeron.logbuffer.Header; -import io.rsocket.aeron.internal.AeronWrapper; -import io.rsocket.aeron.internal.Constants; -import io.rsocket.aeron.internal.EventLoop; -import io.rsocket.aeron.internal.NotConnectedException; -import io.rsocket.aeron.internal.reactivestreams.messages.AckConnectDecoder; -import io.rsocket.aeron.internal.reactivestreams.messages.ConnectEncoder; -import io.rsocket.aeron.internal.reactivestreams.messages.MessageHeaderDecoder; -import io.rsocket.aeron.internal.reactivestreams.messages.MessageHeaderEncoder; -import java.nio.ByteBuffer; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicLong; -import java.util.function.IntConsumer; -import org.agrona.DirectBuffer; -import org.agrona.concurrent.UnsafeBuffer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import reactor.core.publisher.Mono; -import reactor.core.publisher.Operators; - -/** Brokers a connection to a remote Aeron server. */ -public class AeronClientChannelConnector - implements ReactiveStreamsRemote.ClientChannelConnector< - AeronClientChannelConnector.AeronClientConfig, AeronChannel>, - AutoCloseable { - - private static final Logger logger = LoggerFactory.getLogger(AeronClientChannelConnector.class); - - private static final AtomicLong CHANNEL_ID_COUNTER = new AtomicLong(); - - private final AeronWrapper aeronWrapper; - - // Subscriptions clients listen to responses on - private final ConcurrentHashMap clientSubscriptions; - private final ConcurrentHashMap serverSessionIdConsumerMap; - - private final Subscription managementSubscription; - - private final EventLoop eventLoop; - - private volatile boolean running = true; - - private AeronClientChannelConnector( - AeronWrapper aeronWrapper, - AeronSocketAddress managementSubscriptionSocket, - EventLoop eventLoop) { - this.aeronWrapper = aeronWrapper; - - logger.debug( - "client creating a management subscription on channel {}, stream id {}", - managementSubscriptionSocket.getChannel(), - Constants.CLIENT_MANAGEMENT_STREAM_ID); - - this.managementSubscription = - aeronWrapper.addSubscription( - managementSubscriptionSocket.getChannel(), Constants.CLIENT_MANAGEMENT_STREAM_ID); - this.eventLoop = eventLoop; - this.clientSubscriptions = new ConcurrentHashMap<>(); - this.serverSessionIdConsumerMap = new ConcurrentHashMap<>(); - - poll(); - } - - public static AeronClientChannelConnector create( - AeronWrapper wrapper, AeronSocketAddress managementSubscriptionSocket, EventLoop eventLoop) { - return new AeronClientChannelConnector(wrapper, managementSubscriptionSocket, eventLoop); - } - - private final FragmentAssembler fragmentAssembler = - new FragmentAssembler( - new FragmentHandler() { - private final MessageHeaderDecoder messageHeaderDecoder = new MessageHeaderDecoder(); - private final AckConnectDecoder ackConnectDecoder = new AckConnectDecoder(); - - @Override - public void onFragment(DirectBuffer buffer, int offset, int length, Header header) { - messageHeaderDecoder.wrap(buffer, offset); - - // Do not change the order or remove fields - final int actingBlockLength = messageHeaderDecoder.blockLength(); - final int templateId = messageHeaderDecoder.templateId(); - final int schemaId = messageHeaderDecoder.schemaId(); - final int actingVersion = messageHeaderDecoder.version(); - - if (templateId == AckConnectDecoder.TEMPLATE_ID) { - logger.debug("client received an ack message on session id {}", header.sessionId()); - offset += messageHeaderDecoder.encodedLength(); - ackConnectDecoder.wrap(buffer, offset, actingBlockLength, actingVersion); - long channelId = ackConnectDecoder.channelId(); - int serverSessionId = ackConnectDecoder.serverSessionId(); - - logger.debug( - "client received ack message for channel id {} and server session id {}", - channelId, - serverSessionId); - - IntConsumer intConsumer = serverSessionIdConsumerMap.remove(channelId); - - if (intConsumer != null) { - intConsumer.accept(serverSessionId); - } else { - throw new IllegalStateException("no channel found for channel id " + channelId); - } - } else { - throw new IllegalStateException("received unknown template id " + templateId); - } - } - }); - - private int poll() { - int poll; - try { - poll = managementSubscription.poll(fragmentAssembler, 4096); - } finally { - if (running) { - boolean execute = eventLoop.execute(this::poll); - if (!execute) { - running = false; - throw new IllegalStateException("unable to keep polling, eventLoop rejection"); - } - } - } - - return poll; - } - - @Override - public Mono apply(AeronClientConfig aeronClientConfig) { - return Mono.from( - subscriber -> { - subscriber.onSubscribe(Operators.emptySubscription()); - final long channelId = CHANNEL_ID_COUNTER.get(); - try { - - logger.debug("Creating new client channel with id {}", channelId); - final Publication destination = - aeronWrapper.addPublication( - aeronClientConfig.sendSocketAddress.getChannel(), - aeronClientConfig.sendStreamId); - int destinationStreamId = destination.streamId(); - - logger.debug( - "Client created publication to {}, on stream id {}, and session id {}", - aeronClientConfig.sendSocketAddress, - aeronClientConfig.sendStreamId, - destination.sessionId()); - - final Subscription source = - clientSubscriptions.computeIfAbsent( - aeronClientConfig.receiveSocketAddress, - address -> { - Subscription subscription = - aeronWrapper.addSubscription( - aeronClientConfig.receiveSocketAddress.getChannel(), - aeronClientConfig.receiveStreamId); - logger.debug( - "Client created subscription to {}, on stream id {}", - aeronClientConfig.receiveSocketAddress, - aeronClientConfig.receiveStreamId); - return subscription; - }); - - IntConsumer sessionIdConsumer = - sessionId -> { - try { - AeronChannel aeronChannel = - new AeronChannel( - "client", destination, source, aeronClientConfig.eventLoop, sessionId); - logger.debug( - "created client AeronChannel for destination {}, source {}, destination stream id {}, source stream id {}, client session id, and server session id {}", - aeronClientConfig.sendSocketAddress, - aeronClientConfig.receiveSocketAddress, - destination.streamId(), - source.streamId(), - destination.sessionId(), - sessionId); - subscriber.onNext(aeronChannel); - subscriber.onComplete(); - } catch (Throwable t) { - subscriber.onError(t); - } - }; - - serverSessionIdConsumerMap.putIfAbsent(channelId, sessionIdConsumer); - - aeronWrapper.unavailableImageHandlers( - image -> { - if (destinationStreamId == image.sessionId()) { - clientSubscriptions.remove(aeronClientConfig.receiveSocketAddress); - return true; - } else { - return false; - } - }); - - Publication managementPublication = - aeronWrapper.addPublication( - aeronClientConfig.sendSocketAddress.getChannel(), - Constants.SERVER_MANAGEMENT_STREAM_ID); - logger.debug( - "Client created management publication to channel {}, stream id {}", - managementPublication.channel(), - managementPublication.streamId()); - - DirectBuffer buffer = - encodeConnectMessage(channelId, aeronClientConfig, destination.sessionId()); - long offer; - do { - offer = managementPublication.offer(buffer); - if (offer == Publication.CLOSED) { - subscriber.onError(new NotConnectedException()); - } - } while (offer < 0); - logger.debug("Client sent create message to {}", managementPublication.channel()); - - } catch (Throwable t) { - logger.error("Error creating a channel to {}", aeronClientConfig); - clientSubscriptions.remove(aeronClientConfig.receiveSocketAddress); - subscriber.onError(t); - } - }); - } - - public DirectBuffer encodeConnectMessage( - long channelId, AeronClientConfig config, int clientSessionId) { - final ByteBuffer byteBuffer = ByteBuffer.allocateDirect(4096); - final UnsafeBuffer directBuffer = new UnsafeBuffer(byteBuffer); - int bufferOffset = 0; - - MessageHeaderEncoder messageHeaderEncoder = new MessageHeaderEncoder(); - - // Do not channel the order - messageHeaderEncoder - .wrap(directBuffer, bufferOffset) - .blockLength(ConnectEncoder.BLOCK_LENGTH) - .templateId(ConnectEncoder.TEMPLATE_ID) - .schemaId(ConnectEncoder.SCHEMA_ID) - .version(ConnectEncoder.SCHEMA_VERSION); - - bufferOffset += messageHeaderEncoder.encodedLength(); - - ConnectEncoder connectEncoder = new ConnectEncoder(); - - // Do not change the order - connectEncoder - .wrap(directBuffer, bufferOffset) - .channelId(channelId) - .receivingChannel(config.receiveSocketAddress.getChannel()) - .receivingStreamId(config.receiveStreamId) - .sendingChannel(config.sendSocketAddress.getChannel()) - .sendingStreamId(config.sendStreamId) - .clientSessionId(clientSessionId) - .clientManagementChannel(managementSubscription.channel()); - - return directBuffer; - } - - public static class AeronClientConfig implements ReactiveStreamsRemote.ClientChannelConfig { - private final AeronSocketAddress receiveSocketAddress; - private final AeronSocketAddress sendSocketAddress; - private final int receiveStreamId; - private final int sendStreamId; - private final EventLoop eventLoop; - - private AeronClientConfig( - AeronSocketAddress receiveSocketAddress, - AeronSocketAddress sendSocketAddress, - int receiveStreamId, - int sendStreamId, - EventLoop eventLoop) { - this.receiveSocketAddress = receiveSocketAddress; - this.sendSocketAddress = sendSocketAddress; - this.receiveStreamId = receiveStreamId; - this.sendStreamId = sendStreamId; - this.eventLoop = eventLoop; - } - - /** - * Creates client a new {@code AeronClientConfig} for a {@link AeronChannel} - * - * @param receiveSocketAddress the address the channels receives data on - * @param sendSocketAddress the address the channel sends data too - * @param receiveStreamId receiving stream id - * @param sendStreamId the sending stream id - * @param eventLoop event loop for this client - * @return new {@code AeronClientConfig} - */ - public static AeronClientConfig create( - AeronSocketAddress receiveSocketAddress, - AeronSocketAddress sendSocketAddress, - int receiveStreamId, - int sendStreamId, - EventLoop eventLoop) { - return new AeronClientConfig( - receiveSocketAddress, sendSocketAddress, receiveStreamId, sendStreamId, eventLoop); - } - - @Override - public String toString() { - return "AeronClientConfig{" - + "receiveSocketAddress=" - + receiveSocketAddress - + ", sendSocketAddress=" - + sendSocketAddress - + ", receiveStreamId=" - + receiveStreamId - + ", sendStreamId=" - + sendStreamId - + ", eventLoop=" - + eventLoop - + '}'; - } - } - - @Override - public void close() { - running = false; - } -} diff --git a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/AeronInSubscriber.java b/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/AeronInSubscriber.java deleted file mode 100644 index 78cf93c95..000000000 --- a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/AeronInSubscriber.java +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.rsocket.aeron.internal.reactivestreams; - -import io.aeron.Publication; -import io.aeron.logbuffer.BufferClaim; -import io.rsocket.aeron.internal.Constants; -import io.rsocket.aeron.internal.NotConnectedException; -import org.agrona.DirectBuffer; -import org.agrona.MutableDirectBuffer; -import org.agrona.concurrent.OneToOneConcurrentArrayQueue; -import org.reactivestreams.Subscriber; -import org.reactivestreams.Subscription; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** */ -public class AeronInSubscriber implements Subscriber { - private static final Logger logger = LoggerFactory.getLogger(AeronInSubscriber.class); - private static final ThreadLocal bufferClaims = - ThreadLocal.withInitial(BufferClaim::new); - private static final int BUFFER_SIZE = 128; - private static final int REFILL = BUFFER_SIZE / 3; - - private static final OneToOneConcurrentArrayQueue> - queues = new OneToOneConcurrentArrayQueue<>(BUFFER_SIZE); - - private final OneToOneConcurrentArrayQueue buffers; - private final String name; - private final Publication destination; - - private Subscription subscription; - - private volatile boolean complete; - private volatile boolean erred = false; - - private volatile long requested; - - public AeronInSubscriber(String name, Publication destination) { - this.name = name; - this.destination = destination; - OneToOneConcurrentArrayQueue poll; - synchronized (queues) { - poll = queues.poll(); - } - buffers = poll != null ? poll : new OneToOneConcurrentArrayQueue<>(BUFFER_SIZE); - } - - @Override - public synchronized void onSubscribe(Subscription subscription) { - this.subscription = subscription; - requested = BUFFER_SIZE; - subscription.request(BUFFER_SIZE); - } - - @Override - public void onNext(DirectBuffer buffer) { - if (!erred) { - if (logger.isTraceEnabled()) { - logger.trace( - name - + " sending to destination => " - + destination.channel() - + " and aeron stream " - + destination.streamId() - + " and session id " - + destination.sessionId()); - } - boolean offer; - synchronized (buffers) { - offer = buffers.offer(buffer); - } - if (!offer) { - onError(new IllegalStateException("missing back-pressure")); - } - - tryEmit(); - } - } - - private boolean emitting = false; - private boolean missed = false; - - void tryEmit() { - synchronized (this) { - if (emitting) { - missed = true; - return; - } - } - - emit(); - } - - void emit() { - try { - for (; ; ) { - synchronized (this) { - missed = false; - } - while (!buffers.isEmpty()) { - DirectBuffer buffer = buffers.poll(); - tryClaimOrOffer(buffer); - requested--; - if (requested < REFILL) { - synchronized (buffers) { - if (!complete) { - long diff = BUFFER_SIZE - requested; - requested = BUFFER_SIZE; - subscription.request(diff); - } - } - } - } - - synchronized (this) { - if (!missed) { - emitting = false; - break; - } - } - } - } catch (Throwable t) { - onError(t); - } - - if (complete && buffers.isEmpty()) { - synchronized (queues) { - queues.offer(buffers); - } - } - } - - private void tryClaimOrOffer(DirectBuffer buffer) { - boolean successful = false; - - int capacity = buffer.capacity(); - if (capacity < Constants.AERON_MTU_SIZE) { - BufferClaim bufferClaim = bufferClaims.get(); - - while (!successful) { - long offer = destination.tryClaim(capacity, bufferClaim); - if (offer >= 0) { - try { - final MutableDirectBuffer b = bufferClaim.buffer(); - int offset = bufferClaim.offset(); - b.putBytes(offset, buffer, 0, capacity); - } finally { - bufferClaim.commit(); - successful = true; - } - } else { - if (offer == Publication.CLOSED) { - onError(new NotConnectedException(name)); - } - - successful = false; - } - } - - } else { - while (!successful) { - long offer = destination.offer(buffer); - - if (offer < 0) { - if (offer == Publication.CLOSED) { - onError(new NotConnectedException(name)); - } - } else { - successful = true; - } - } - } - } - - @Override - public synchronized void onError(Throwable t) { - if (!erred) { - erred = true; - subscription.cancel(); - } - - t.printStackTrace(); - } - - @Override - public synchronized void onComplete() { - complete = true; - tryEmit(); - } - - @Override - public String toString() { - return "AeronInSubscriber{" + "name='" + name + '\'' + '}'; - } -} diff --git a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/AeronOutPublisher.java b/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/AeronOutPublisher.java deleted file mode 100644 index 7732c3160..000000000 --- a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/AeronOutPublisher.java +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.rsocket.aeron.internal.reactivestreams; - -import io.aeron.ControlledFragmentAssembler; -import io.aeron.logbuffer.ControlledFragmentHandler; -import io.aeron.logbuffer.Header; -import io.rsocket.aeron.internal.EventLoop; -import io.rsocket.aeron.internal.NotConnectedException; -import java.nio.ByteBuffer; -import java.util.Objects; -import java.util.function.IntSupplier; -import org.agrona.DirectBuffer; -import org.agrona.concurrent.UnsafeBuffer; -import org.reactivestreams.Subscriber; -import org.reactivestreams.Subscription; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import reactor.core.CoreSubscriber; -import reactor.core.publisher.Flux; - -/** */ -public class AeronOutPublisher extends Flux { - private static final Logger logger = LoggerFactory.getLogger(AeronOutPublisher.class); - private final io.aeron.Subscription source; - private final EventLoop eventLoop; - - private String name; - private volatile long requested; - private volatile long processed; - private Subscriber destination; - private AeronOutProcessorSubscription subscription; - private final int sessionId; - - /** - * Creates a publication for a unique session - * - * @param name publication's name - * @param sessionId sessionId between the source and the remote publication - * @param source Aeron {@code Subscription} publish data from - * @param eventLoop {@link EventLoop} to poll the source with - */ - public AeronOutPublisher( - String name, int sessionId, io.aeron.Subscription source, EventLoop eventLoop) { - this.name = name; - this.source = source; - this.eventLoop = eventLoop; - this.sessionId = sessionId; - } - - @Override - public void subscribe(CoreSubscriber destination) { - Objects.requireNonNull(destination); - synchronized (this) { - if (this.destination != null && subscription.canEmit()) { - throw new IllegalStateException( - "only allows one subscription => channel " - + source.channel() - + " and stream id => " - + source.streamId()); - } - this.destination = destination; - } - - this.subscription = new AeronOutProcessorSubscription(destination); - destination.onSubscribe(subscription); - } - - void onError(Throwable t) { - subscription.erred = true; - if (destination != null) { - destination.onError(t); - } - } - - void cancel() { - if (subscription != null) { - subscription.cancel(); - } - } - - @Override - public String toString() { - return "AeronOutPublisher{" + "name='" + name + '\'' + '}'; - } - - private class AeronOutProcessorSubscription implements Subscription { - private volatile boolean erred = false; - private volatile boolean cancelled = false; - private final Subscriber destination; - private final ControlledFragmentAssembler assembler; - - public AeronOutProcessorSubscription(Subscriber destination) { - this.destination = destination; - this.assembler = new ControlledFragmentAssembler(this::onFragment, 4096); - } - - boolean emitting = false; - boolean missed = false; - - @Override - public void request(long n) { - if (n < 0) { - onError(new IllegalStateException("n must be greater than zero")); - } - - synchronized (AeronOutPublisher.this) { - long r; - if (requested != Long.MAX_VALUE && n > 0) { - r = requested + n; - requested = r < 0 ? Long.MAX_VALUE : r; - } - } - - tryEmit(); - } - - // allocate this once - final IntSupplier supplier = this::emit; - - void tryEmit() { - synchronized (AeronOutPublisher.this) { - if (emitting) { - missed = true; - return; - } - emitting = true; - eventLoop.execute(supplier); - } - } - - ControlledFragmentHandler.Action onFragment( - DirectBuffer buffer, int offset, int length, Header header) { - if (sessionId != header.sessionId()) { - if (source.imageBySessionId(header.sessionId()) == null) { - return ControlledFragmentHandler.Action.CONTINUE; - } - - return ControlledFragmentHandler.Action.ABORT; - } - - try { - ByteBuffer bytes = ByteBuffer.allocate(length); - buffer.getBytes(offset, bytes, length); - - if (canEmit()) { - destination.onNext(new UnsafeBuffer(bytes)); - } - } catch (Throwable t) { - onError(t); - } - - return ControlledFragmentHandler.Action.COMMIT; - } - - int emit() { - int emitted = 0; - for (; ; ) { - synchronized (AeronOutPublisher.this) { - missed = false; - } - - try { - if (source.isClosed()) { - onError(new NotConnectedException(name)); - return 0; - } - - while (processed < requested) { - - int poll = source.controlledPoll(assembler, 4096); - - if (poll < 1) { - break; - } else { - emitted++; - processed++; - } - } - - synchronized (AeronOutPublisher.this) { - emitting = false; - break; - } - - } catch (Throwable t) { - onError(t); - } - } - - if (canEmit()) { - tryEmit(); - } - - return emitted; - } - - @Override - public void cancel() { - cancelled = true; - } - - private boolean canEmit() { - return !cancelled && !erred; - } - } -} diff --git a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/AeronSocketAddress.java b/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/AeronSocketAddress.java deleted file mode 100644 index ca8926add..000000000 --- a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/AeronSocketAddress.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.rsocket.aeron.internal.reactivestreams; - -import java.net.SocketAddress; - -/** SocketAddress that represents an Aeron Channel */ -public class AeronSocketAddress extends SocketAddress { - private static final String FORMAT = "%s?endpoint=%s:%d"; - private static final long serialVersionUID = -7691068719112973697L; - private final String protocol; - private final String host; - private final int port; - private final String channel; - - private AeronSocketAddress(String protocol, String host, int port) { - this.protocol = protocol; - this.host = host; - this.port = port; - this.channel = String.format(FORMAT, protocol, host, port); - } - - public static AeronSocketAddress create(String protocol, String host, int port) { - return new AeronSocketAddress(protocol, host, port); - } - - public String getProtocol() { - return protocol; - } - - public String getHost() { - return host; - } - - public int getPort() { - return port; - } - - public String getChannel() { - return channel; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - AeronSocketAddress that = (AeronSocketAddress) o; - - return channel != null ? channel.equals(that.channel) : that.channel == null; - } - - @Override - public int hashCode() { - return channel != null ? channel.hashCode() : 0; - } - - @Override - public String toString() { - return "AeronSocketAddress{" - + "protocol='" - + protocol - + '\'' - + ", host='" - + host - + '\'' - + ", port=" - + port - + ", channel='" - + channel - + '\'' - + '}'; - } -} diff --git a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/ReactiveStreamsRemote.java b/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/ReactiveStreamsRemote.java deleted file mode 100644 index f2a8666b9..000000000 --- a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/ReactiveStreamsRemote.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.rsocket.aeron.internal.reactivestreams; - -import io.rsocket.Closeable; -import java.net.SocketAddress; -import java.util.concurrent.TimeUnit; -import java.util.function.Consumer; -import java.util.function.Function; -import org.reactivestreams.Publisher; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - -/** Interfaces to define a ReactiveStream over a remote channel */ -public interface ReactiveStreamsRemote { - interface Channel { - Mono send(Flux in); - - default Mono send(T t) { - return send(Flux.just(t)); - } - - Flux receive(); - } - - interface ClientChannelConnector> - extends Function> {} - - interface ClientChannelConfig {} - - interface ChannelConsumer> extends Consumer {} - - abstract class ChannelServer> { - protected final C channelConsumer; - - public ChannelServer(C channelConsumer) { - this.channelConsumer = channelConsumer; - } - - public abstract StartedServer start(); - } - - interface StartedServer extends Closeable { - /** - * Address for this server. - * - * @return Address for this server. - */ - SocketAddress getServerAddress(); - - /** - * Port for this server. - * - * @return Port for this server. - */ - int getServerPort(); - - /** - * Blocks till this server shutsdown. - * - *

This does not shutdown the server. - */ - void awaitShutdown(); - - /** - * Blocks till this server shutsdown till the passed duration. - * - *

This does not shutdown the server. - * - * @param duration the number of durationUnit to wait - * @param durationUnit the unit e.g. seconds - */ - void awaitShutdown(long duration, TimeUnit durationUnit); - - /** Initiates the shutdown of this server. */ - void shutdown(); - } -} diff --git a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/messages/AckConnectDecoder.java b/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/messages/AckConnectDecoder.java deleted file mode 100644 index 626c1f6d8..000000000 --- a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/messages/AckConnectDecoder.java +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* Generated SBE (Simple Binary Encoding) message codec */ - -package io.rsocket.aeron.internal.reactivestreams.messages; - -import org.agrona.DirectBuffer; - -@javax.annotation.Generated( - value = {"io.rsocket.aeron.internal.reactivestreams.messages.AckConnectDecoder"} -) -@SuppressWarnings("all") -public class AckConnectDecoder { - public static final int BLOCK_LENGTH = 12; - public static final int TEMPLATE_ID = 2; - public static final int SCHEMA_ID = 1; - public static final int SCHEMA_VERSION = 0; - - private final AckConnectDecoder parentMessage = this; - private DirectBuffer buffer; - protected int offset; - protected int limit; - protected int actingBlockLength; - protected int actingVersion; - - public int sbeBlockLength() { - return BLOCK_LENGTH; - } - - public int sbeTemplateId() { - return TEMPLATE_ID; - } - - public int sbeSchemaId() { - return SCHEMA_ID; - } - - public int sbeSchemaVersion() { - return SCHEMA_VERSION; - } - - public String sbeSemanticType() { - return ""; - } - - public int offset() { - return offset; - } - - public AckConnectDecoder wrap( - final DirectBuffer buffer, - final int offset, - final int actingBlockLength, - final int actingVersion) { - this.buffer = buffer; - this.offset = offset; - this.actingBlockLength = actingBlockLength; - this.actingVersion = actingVersion; - limit(offset + actingBlockLength); - - return this; - } - - public int encodedLength() { - return limit - offset; - } - - public int limit() { - return limit; - } - - public void limit(final int limit) { - this.limit = limit; - } - - public static int channelIdId() { - return 1; - } - - public static String channelIdMetaAttribute(final MetaAttribute metaAttribute) { - switch (metaAttribute) { - case EPOCH: - return "unix"; - case TIME_UNIT: - return "nanosecond"; - case SEMANTIC_TYPE: - return ""; - } - - return ""; - } - - public static long channelIdNullValue() { - return -9223372036854775808L; - } - - public static long channelIdMinValue() { - return -9223372036854775807L; - } - - public static long channelIdMaxValue() { - return 9223372036854775807L; - } - - public long channelId() { - return buffer.getLong(offset + 0, java.nio.ByteOrder.LITTLE_ENDIAN); - } - - public static int serverSessionIdId() { - return 2; - } - - public static String serverSessionIdMetaAttribute(final MetaAttribute metaAttribute) { - switch (metaAttribute) { - case EPOCH: - return "unix"; - case TIME_UNIT: - return "nanosecond"; - case SEMANTIC_TYPE: - return ""; - } - - return ""; - } - - public static int serverSessionIdNullValue() { - return -2147483648; - } - - public static int serverSessionIdMinValue() { - return -2147483647; - } - - public static int serverSessionIdMaxValue() { - return 2147483647; - } - - public int serverSessionId() { - return buffer.getInt(offset + 8, java.nio.ByteOrder.LITTLE_ENDIAN); - } - - public String toString() { - return appendTo(new StringBuilder(100)).toString(); - } - - public StringBuilder appendTo(final StringBuilder builder) { - final int originalLimit = limit(); - limit(offset + actingBlockLength); - builder.append("[AckConnect](sbeTemplateId="); - builder.append(TEMPLATE_ID); - builder.append("|sbeSchemaId="); - builder.append(SCHEMA_ID); - builder.append("|sbeSchemaVersion="); - if (actingVersion != SCHEMA_VERSION) { - builder.append(actingVersion); - builder.append('/'); - } - builder.append(SCHEMA_VERSION); - builder.append("|sbeBlockLength="); - if (actingBlockLength != BLOCK_LENGTH) { - builder.append(actingBlockLength); - builder.append('/'); - } - builder.append(BLOCK_LENGTH); - builder.append("):"); - // Token{signal=BEGIN_FIELD, name='channelId', description='The AeronChannel id', id=1, - // version=0, encodedLength=0, offset=0, componentTokenCount=3, - // encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, - // minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', - // epoch='unix', timeUnit=nanosecond, semanticType='null'}} - // Token{signal=ENCODING, name='int64', description='The AeronChannel id', id=-1, version=0, - // encodedLength=8, offset=0, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, - // primitiveType=INT64, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, - // constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, - // semanticType='null'}} - builder.append("channelId="); - builder.append(channelId()); - builder.append('|'); - // Token{signal=BEGIN_FIELD, name='serverSessionId', description='The session id for the server - // publication', id=2, version=0, encodedLength=0, offset=8, componentTokenCount=3, - // encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, - // minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', - // epoch='unix', timeUnit=nanosecond, semanticType='null'}} - // Token{signal=ENCODING, name='int32', description='The session id for the server publication', - // id=-1, version=0, encodedLength=4, offset=8, componentTokenCount=1, - // encoding=Encoding{presence=REQUIRED, primitiveType=INT32, byteOrder=LITTLE_ENDIAN, - // minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', - // epoch='unix', timeUnit=nanosecond, semanticType='null'}} - builder.append("serverSessionId="); - builder.append(serverSessionId()); - - limit(originalLimit); - - return builder; - } -} diff --git a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/messages/AckConnectEncoder.java b/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/messages/AckConnectEncoder.java deleted file mode 100644 index 05fef8487..000000000 --- a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/messages/AckConnectEncoder.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* Generated SBE (Simple Binary Encoding) message codec */ - -package io.rsocket.aeron.internal.reactivestreams.messages; - -import org.agrona.MutableDirectBuffer; - -@javax.annotation.Generated( - value = {"io.rsocket.aeron.internal.reactivestreams.messages.AckConnectEncoder"} -) -@SuppressWarnings("all") -public class AckConnectEncoder { - public static final int BLOCK_LENGTH = 12; - public static final int TEMPLATE_ID = 2; - public static final int SCHEMA_ID = 1; - public static final int SCHEMA_VERSION = 0; - - private final AckConnectEncoder parentMessage = this; - private MutableDirectBuffer buffer; - protected int offset; - protected int limit; - protected int actingBlockLength; - protected int actingVersion; - - public int sbeBlockLength() { - return BLOCK_LENGTH; - } - - public int sbeTemplateId() { - return TEMPLATE_ID; - } - - public int sbeSchemaId() { - return SCHEMA_ID; - } - - public int sbeSchemaVersion() { - return SCHEMA_VERSION; - } - - public String sbeSemanticType() { - return ""; - } - - public int offset() { - return offset; - } - - public AckConnectEncoder wrap(final MutableDirectBuffer buffer, final int offset) { - this.buffer = buffer; - this.offset = offset; - limit(offset + BLOCK_LENGTH); - - return this; - } - - public int encodedLength() { - return limit - offset; - } - - public int limit() { - return limit; - } - - public void limit(final int limit) { - this.limit = limit; - } - - public static long channelIdNullValue() { - return -9223372036854775808L; - } - - public static long channelIdMinValue() { - return -9223372036854775807L; - } - - public static long channelIdMaxValue() { - return 9223372036854775807L; - } - - public AckConnectEncoder channelId(final long value) { - buffer.putLong(offset + 0, value, java.nio.ByteOrder.LITTLE_ENDIAN); - return this; - } - - public static int serverSessionIdNullValue() { - return -2147483648; - } - - public static int serverSessionIdMinValue() { - return -2147483647; - } - - public static int serverSessionIdMaxValue() { - return 2147483647; - } - - public AckConnectEncoder serverSessionId(final int value) { - buffer.putInt(offset + 8, value, java.nio.ByteOrder.LITTLE_ENDIAN); - return this; - } - - public String toString() { - return appendTo(new StringBuilder(100)).toString(); - } - - public StringBuilder appendTo(final StringBuilder builder) { - AckConnectDecoder writer = new AckConnectDecoder(); - writer.wrap(buffer, offset, BLOCK_LENGTH, SCHEMA_VERSION); - - return writer.appendTo(builder); - } -} diff --git a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/messages/ConnectDecoder.java b/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/messages/ConnectDecoder.java deleted file mode 100644 index cd294a48b..000000000 --- a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/messages/ConnectDecoder.java +++ /dev/null @@ -1,549 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* Generated SBE (Simple Binary Encoding) message codec */ - -package io.rsocket.aeron.internal.reactivestreams.messages; - -import org.agrona.DirectBuffer; -import org.agrona.MutableDirectBuffer; - -@javax.annotation.Generated( - value = {"io.rsocket.aeron.internal.reactivestreams.messages.ConnectDecoder"} -) -@SuppressWarnings("all") -public class ConnectDecoder { - public static final int BLOCK_LENGTH = 20; - public static final int TEMPLATE_ID = 1; - public static final int SCHEMA_ID = 1; - public static final int SCHEMA_VERSION = 0; - - private final ConnectDecoder parentMessage = this; - private DirectBuffer buffer; - protected int offset; - protected int limit; - protected int actingBlockLength; - protected int actingVersion; - - public int sbeBlockLength() { - return BLOCK_LENGTH; - } - - public int sbeTemplateId() { - return TEMPLATE_ID; - } - - public int sbeSchemaId() { - return SCHEMA_ID; - } - - public int sbeSchemaVersion() { - return SCHEMA_VERSION; - } - - public String sbeSemanticType() { - return ""; - } - - public int offset() { - return offset; - } - - public ConnectDecoder wrap( - final DirectBuffer buffer, - final int offset, - final int actingBlockLength, - final int actingVersion) { - this.buffer = buffer; - this.offset = offset; - this.actingBlockLength = actingBlockLength; - this.actingVersion = actingVersion; - limit(offset + actingBlockLength); - - return this; - } - - public int encodedLength() { - return limit - offset; - } - - public int limit() { - return limit; - } - - public void limit(final int limit) { - this.limit = limit; - } - - public static int channelIdId() { - return 1; - } - - public static String channelIdMetaAttribute(final MetaAttribute metaAttribute) { - switch (metaAttribute) { - case EPOCH: - return "unix"; - case TIME_UNIT: - return "nanosecond"; - case SEMANTIC_TYPE: - return ""; - } - - return ""; - } - - public static long channelIdNullValue() { - return -9223372036854775808L; - } - - public static long channelIdMinValue() { - return -9223372036854775807L; - } - - public static long channelIdMaxValue() { - return 9223372036854775807L; - } - - public long channelId() { - return buffer.getLong(offset + 0, java.nio.ByteOrder.LITTLE_ENDIAN); - } - - public static int sendingStreamIdId() { - return 2; - } - - public static String sendingStreamIdMetaAttribute(final MetaAttribute metaAttribute) { - switch (metaAttribute) { - case EPOCH: - return "unix"; - case TIME_UNIT: - return "nanosecond"; - case SEMANTIC_TYPE: - return ""; - } - - return ""; - } - - public static int sendingStreamIdNullValue() { - return -2147483648; - } - - public static int sendingStreamIdMinValue() { - return -2147483647; - } - - public static int sendingStreamIdMaxValue() { - return 2147483647; - } - - public int sendingStreamId() { - return buffer.getInt(offset + 8, java.nio.ByteOrder.LITTLE_ENDIAN); - } - - public static int receivingStreamIdId() { - return 3; - } - - public static String receivingStreamIdMetaAttribute(final MetaAttribute metaAttribute) { - switch (metaAttribute) { - case EPOCH: - return "unix"; - case TIME_UNIT: - return "nanosecond"; - case SEMANTIC_TYPE: - return ""; - } - - return ""; - } - - public static int receivingStreamIdNullValue() { - return -2147483648; - } - - public static int receivingStreamIdMinValue() { - return -2147483647; - } - - public static int receivingStreamIdMaxValue() { - return 2147483647; - } - - public int receivingStreamId() { - return buffer.getInt(offset + 12, java.nio.ByteOrder.LITTLE_ENDIAN); - } - - public static int clientSessionIdId() { - return 4; - } - - public static String clientSessionIdMetaAttribute(final MetaAttribute metaAttribute) { - switch (metaAttribute) { - case EPOCH: - return "unix"; - case TIME_UNIT: - return "nanosecond"; - case SEMANTIC_TYPE: - return ""; - } - - return ""; - } - - public static int clientSessionIdNullValue() { - return -2147483648; - } - - public static int clientSessionIdMinValue() { - return -2147483647; - } - - public static int clientSessionIdMaxValue() { - return 2147483647; - } - - public int clientSessionId() { - return buffer.getInt(offset + 16, java.nio.ByteOrder.LITTLE_ENDIAN); - } - - public static int sendingChannelId() { - return 5; - } - - public static String sendingChannelCharacterEncoding() { - return "UTF-8"; - } - - public static String sendingChannelMetaAttribute(final MetaAttribute metaAttribute) { - switch (metaAttribute) { - case EPOCH: - return "unix"; - case TIME_UNIT: - return "nanosecond"; - case SEMANTIC_TYPE: - return ""; - } - - return ""; - } - - public static int sendingChannelHeaderLength() { - return 4; - } - - public int sendingChannelLength() { - final int limit = parentMessage.limit(); - return (int) (buffer.getInt(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF_FFFFL); - } - - public int getSendingChannel( - final MutableDirectBuffer dst, final int dstOffset, final int length) { - final int headerLength = 4; - final int limit = parentMessage.limit(); - final int dataLength = - (int) (buffer.getInt(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF_FFFFL); - final int bytesCopied = Math.min(length, dataLength); - parentMessage.limit(limit + headerLength + dataLength); - buffer.getBytes(limit + headerLength, dst, dstOffset, bytesCopied); - - return bytesCopied; - } - - public int getSendingChannel(final byte[] dst, final int dstOffset, final int length) { - final int headerLength = 4; - final int limit = parentMessage.limit(); - final int dataLength = - (int) (buffer.getInt(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF_FFFFL); - final int bytesCopied = Math.min(length, dataLength); - parentMessage.limit(limit + headerLength + dataLength); - buffer.getBytes(limit + headerLength, dst, dstOffset, bytesCopied); - - return bytesCopied; - } - - public String sendingChannel() { - final int headerLength = 4; - final int limit = parentMessage.limit(); - final int dataLength = - (int) (buffer.getInt(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF_FFFFL); - parentMessage.limit(limit + headerLength + dataLength); - final byte[] tmp = new byte[dataLength]; - buffer.getBytes(limit + headerLength, tmp, 0, dataLength); - - final String value; - try { - value = new String(tmp, "UTF-8"); - } catch (final java.io.UnsupportedEncodingException ex) { - throw new RuntimeException(ex); - } - - return value; - } - - public static int receivingChannelId() { - return 6; - } - - public static String receivingChannelCharacterEncoding() { - return "UTF-8"; - } - - public static String receivingChannelMetaAttribute(final MetaAttribute metaAttribute) { - switch (metaAttribute) { - case EPOCH: - return "unix"; - case TIME_UNIT: - return "nanosecond"; - case SEMANTIC_TYPE: - return ""; - } - - return ""; - } - - public static int receivingChannelHeaderLength() { - return 4; - } - - public int receivingChannelLength() { - final int limit = parentMessage.limit(); - return (int) (buffer.getInt(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF_FFFFL); - } - - public int getReceivingChannel( - final MutableDirectBuffer dst, final int dstOffset, final int length) { - final int headerLength = 4; - final int limit = parentMessage.limit(); - final int dataLength = - (int) (buffer.getInt(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF_FFFFL); - final int bytesCopied = Math.min(length, dataLength); - parentMessage.limit(limit + headerLength + dataLength); - buffer.getBytes(limit + headerLength, dst, dstOffset, bytesCopied); - - return bytesCopied; - } - - public int getReceivingChannel(final byte[] dst, final int dstOffset, final int length) { - final int headerLength = 4; - final int limit = parentMessage.limit(); - final int dataLength = - (int) (buffer.getInt(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF_FFFFL); - final int bytesCopied = Math.min(length, dataLength); - parentMessage.limit(limit + headerLength + dataLength); - buffer.getBytes(limit + headerLength, dst, dstOffset, bytesCopied); - - return bytesCopied; - } - - public String receivingChannel() { - final int headerLength = 4; - final int limit = parentMessage.limit(); - final int dataLength = - (int) (buffer.getInt(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF_FFFFL); - parentMessage.limit(limit + headerLength + dataLength); - final byte[] tmp = new byte[dataLength]; - buffer.getBytes(limit + headerLength, tmp, 0, dataLength); - - final String value; - try { - value = new String(tmp, "UTF-8"); - } catch (final java.io.UnsupportedEncodingException ex) { - throw new RuntimeException(ex); - } - - return value; - } - - public static int clientManagementChannelId() { - return 6; - } - - public static String clientManagementChannelCharacterEncoding() { - return "UTF-8"; - } - - public static String clientManagementChannelMetaAttribute(final MetaAttribute metaAttribute) { - switch (metaAttribute) { - case EPOCH: - return "unix"; - case TIME_UNIT: - return "nanosecond"; - case SEMANTIC_TYPE: - return ""; - } - - return ""; - } - - public static int clientManagementChannelHeaderLength() { - return 4; - } - - public int clientManagementChannelLength() { - final int limit = parentMessage.limit(); - return (int) (buffer.getInt(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF_FFFFL); - } - - public int getClientManagementChannel( - final MutableDirectBuffer dst, final int dstOffset, final int length) { - final int headerLength = 4; - final int limit = parentMessage.limit(); - final int dataLength = - (int) (buffer.getInt(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF_FFFFL); - final int bytesCopied = Math.min(length, dataLength); - parentMessage.limit(limit + headerLength + dataLength); - buffer.getBytes(limit + headerLength, dst, dstOffset, bytesCopied); - - return bytesCopied; - } - - public int getClientManagementChannel(final byte[] dst, final int dstOffset, final int length) { - final int headerLength = 4; - final int limit = parentMessage.limit(); - final int dataLength = - (int) (buffer.getInt(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF_FFFFL); - final int bytesCopied = Math.min(length, dataLength); - parentMessage.limit(limit + headerLength + dataLength); - buffer.getBytes(limit + headerLength, dst, dstOffset, bytesCopied); - - return bytesCopied; - } - - public String clientManagementChannel() { - final int headerLength = 4; - final int limit = parentMessage.limit(); - final int dataLength = - (int) (buffer.getInt(limit, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF_FFFFL); - parentMessage.limit(limit + headerLength + dataLength); - final byte[] tmp = new byte[dataLength]; - buffer.getBytes(limit + headerLength, tmp, 0, dataLength); - - final String value; - try { - value = new String(tmp, "UTF-8"); - } catch (final java.io.UnsupportedEncodingException ex) { - throw new RuntimeException(ex); - } - - return value; - } - - public String toString() { - return appendTo(new StringBuilder(100)).toString(); - } - - public StringBuilder appendTo(final StringBuilder builder) { - final int originalLimit = limit(); - limit(offset + actingBlockLength); - builder.append("[Connect](sbeTemplateId="); - builder.append(TEMPLATE_ID); - builder.append("|sbeSchemaId="); - builder.append(SCHEMA_ID); - builder.append("|sbeSchemaVersion="); - if (actingVersion != SCHEMA_VERSION) { - builder.append(actingVersion); - builder.append('/'); - } - builder.append(SCHEMA_VERSION); - builder.append("|sbeBlockLength="); - if (actingBlockLength != BLOCK_LENGTH) { - builder.append(actingBlockLength); - builder.append('/'); - } - builder.append(BLOCK_LENGTH); - builder.append("):"); - // Token{signal=BEGIN_FIELD, name='channelId', description='The AeronChannel id', id=1, - // version=0, encodedLength=0, offset=0, componentTokenCount=3, - // encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, - // minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', - // epoch='unix', timeUnit=nanosecond, semanticType='null'}} - // Token{signal=ENCODING, name='int64', description='The AeronChannel id', id=-1, version=0, - // encodedLength=8, offset=0, componentTokenCount=1, encoding=Encoding{presence=REQUIRED, - // primitiveType=INT64, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, - // constValue=null, characterEncoding='null', epoch='unix', timeUnit=nanosecond, - // semanticType='null'}} - builder.append("channelId="); - builder.append(channelId()); - builder.append('|'); - // Token{signal=BEGIN_FIELD, name='sendingStreamId', description='The stream id the connecting - // client will send traffic on', id=2, version=0, encodedLength=0, offset=8, - // componentTokenCount=3, encoding=Encoding{presence=REQUIRED, primitiveType=null, - // byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, - // characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} - // Token{signal=ENCODING, name='int32', description='The stream id the connecting client will - // send traffic on', id=-1, version=0, encodedLength=4, offset=8, componentTokenCount=1, - // encoding=Encoding{presence=REQUIRED, primitiveType=INT32, byteOrder=LITTLE_ENDIAN, - // minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', - // epoch='unix', timeUnit=nanosecond, semanticType='null'}} - builder.append("sendingStreamId="); - builder.append(sendingStreamId()); - builder.append('|'); - // Token{signal=BEGIN_FIELD, name='receivingStreamId', description='The stream id the connecting - // client will receive data on', id=3, version=0, encodedLength=0, offset=12, - // componentTokenCount=3, encoding=Encoding{presence=REQUIRED, primitiveType=null, - // byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, - // characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} - // Token{signal=ENCODING, name='int32', description='The stream id the connecting client will - // receive data on', id=-1, version=0, encodedLength=4, offset=12, componentTokenCount=1, - // encoding=Encoding{presence=REQUIRED, primitiveType=INT32, byteOrder=LITTLE_ENDIAN, - // minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', - // epoch='unix', timeUnit=nanosecond, semanticType='null'}} - builder.append("receivingStreamId="); - builder.append(receivingStreamId()); - builder.append('|'); - // Token{signal=BEGIN_FIELD, name='clientSessionId', description='The session id for the client - // publication', id=4, version=0, encodedLength=0, offset=16, componentTokenCount=3, - // encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, - // minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', - // epoch='unix', timeUnit=nanosecond, semanticType='null'}} - // Token{signal=ENCODING, name='int32', description='The session id for the client publication', - // id=-1, version=0, encodedLength=4, offset=16, componentTokenCount=1, - // encoding=Encoding{presence=REQUIRED, primitiveType=INT32, byteOrder=LITTLE_ENDIAN, - // minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', - // epoch='unix', timeUnit=nanosecond, semanticType='null'}} - builder.append("clientSessionId="); - builder.append(clientSessionId()); - builder.append('|'); - // Token{signal=BEGIN_VAR_DATA, name='sendingChannel', description='The Aeron channel the client - // will send data on', id=5, version=0, encodedLength=0, offset=20, componentTokenCount=6, - // encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, - // minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', - // epoch='unix', timeUnit=nanosecond, semanticType='null'}} - builder.append("sendingChannel="); - builder.append(sendingChannel()); - builder.append('|'); - // Token{signal=BEGIN_VAR_DATA, name='receivingChannel', description='The Aeron channel the - // client will receive data on', id=6, version=0, encodedLength=0, offset=-1, - // componentTokenCount=6, encoding=Encoding{presence=REQUIRED, primitiveType=null, - // byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, - // characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} - builder.append("receivingChannel="); - builder.append(receivingChannel()); - builder.append('|'); - // Token{signal=BEGIN_VAR_DATA, name='clientManagementChannel', description='The channel the - // client listens for management data on', id=6, version=0, encodedLength=0, offset=-1, - // componentTokenCount=6, encoding=Encoding{presence=REQUIRED, primitiveType=null, - // byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, - // characterEncoding='null', epoch='unix', timeUnit=nanosecond, semanticType='null'}} - builder.append("clientManagementChannel="); - builder.append(clientManagementChannel()); - - limit(originalLimit); - - return builder; - } -} diff --git a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/messages/ConnectEncoder.java b/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/messages/ConnectEncoder.java deleted file mode 100644 index 140a5a293..000000000 --- a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/messages/ConnectEncoder.java +++ /dev/null @@ -1,393 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* Generated SBE (Simple Binary Encoding) message codec */ - -package io.rsocket.aeron.internal.reactivestreams.messages; - -import org.agrona.DirectBuffer; -import org.agrona.MutableDirectBuffer; - -@javax.annotation.Generated( - value = {"io.rsocket.aeron.internal.reactivestreams.messages.ConnectEncoder"} -) -@SuppressWarnings("all") -public class ConnectEncoder { - public static final int BLOCK_LENGTH = 20; - public static final int TEMPLATE_ID = 1; - public static final int SCHEMA_ID = 1; - public static final int SCHEMA_VERSION = 0; - - private final ConnectEncoder parentMessage = this; - private MutableDirectBuffer buffer; - protected int offset; - protected int limit; - protected int actingBlockLength; - protected int actingVersion; - - public int sbeBlockLength() { - return BLOCK_LENGTH; - } - - public int sbeTemplateId() { - return TEMPLATE_ID; - } - - public int sbeSchemaId() { - return SCHEMA_ID; - } - - public int sbeSchemaVersion() { - return SCHEMA_VERSION; - } - - public String sbeSemanticType() { - return ""; - } - - public int offset() { - return offset; - } - - public ConnectEncoder wrap(final MutableDirectBuffer buffer, final int offset) { - this.buffer = buffer; - this.offset = offset; - limit(offset + BLOCK_LENGTH); - - return this; - } - - public int encodedLength() { - return limit - offset; - } - - public int limit() { - return limit; - } - - public void limit(final int limit) { - this.limit = limit; - } - - public static long channelIdNullValue() { - return -9223372036854775808L; - } - - public static long channelIdMinValue() { - return -9223372036854775807L; - } - - public static long channelIdMaxValue() { - return 9223372036854775807L; - } - - public ConnectEncoder channelId(final long value) { - buffer.putLong(offset + 0, value, java.nio.ByteOrder.LITTLE_ENDIAN); - return this; - } - - public static int sendingStreamIdNullValue() { - return -2147483648; - } - - public static int sendingStreamIdMinValue() { - return -2147483647; - } - - public static int sendingStreamIdMaxValue() { - return 2147483647; - } - - public ConnectEncoder sendingStreamId(final int value) { - buffer.putInt(offset + 8, value, java.nio.ByteOrder.LITTLE_ENDIAN); - return this; - } - - public static int receivingStreamIdNullValue() { - return -2147483648; - } - - public static int receivingStreamIdMinValue() { - return -2147483647; - } - - public static int receivingStreamIdMaxValue() { - return 2147483647; - } - - public ConnectEncoder receivingStreamId(final int value) { - buffer.putInt(offset + 12, value, java.nio.ByteOrder.LITTLE_ENDIAN); - return this; - } - - public static int clientSessionIdNullValue() { - return -2147483648; - } - - public static int clientSessionIdMinValue() { - return -2147483647; - } - - public static int clientSessionIdMaxValue() { - return 2147483647; - } - - public ConnectEncoder clientSessionId(final int value) { - buffer.putInt(offset + 16, value, java.nio.ByteOrder.LITTLE_ENDIAN); - return this; - } - - public static int sendingChannelId() { - return 5; - } - - public static String sendingChannelCharacterEncoding() { - return "UTF-8"; - } - - public static String sendingChannelMetaAttribute(final MetaAttribute metaAttribute) { - switch (metaAttribute) { - case EPOCH: - return "unix"; - case TIME_UNIT: - return "nanosecond"; - case SEMANTIC_TYPE: - return ""; - } - - return ""; - } - - public static int sendingChannelHeaderLength() { - return 4; - } - - public ConnectEncoder putSendingChannel( - final DirectBuffer src, final int srcOffset, final int length) { - if (length > 1073741824) { - throw new IllegalArgumentException("length > max value for type: " + length); - } - - final int headerLength = 4; - final int limit = parentMessage.limit(); - parentMessage.limit(limit + headerLength + length); - buffer.putInt(limit, length, java.nio.ByteOrder.LITTLE_ENDIAN); - buffer.putBytes(limit + headerLength, src, srcOffset, length); - - return this; - } - - public ConnectEncoder putSendingChannel(final byte[] src, final int srcOffset, final int length) { - if (length > 1073741824) { - throw new IllegalArgumentException("length > max value for type: " + length); - } - - final int headerLength = 4; - final int limit = parentMessage.limit(); - parentMessage.limit(limit + headerLength + length); - buffer.putInt(limit, length, java.nio.ByteOrder.LITTLE_ENDIAN); - buffer.putBytes(limit + headerLength, src, srcOffset, length); - - return this; - } - - public ConnectEncoder sendingChannel(final String value) { - final byte[] bytes; - try { - bytes = value.getBytes("UTF-8"); - } catch (final java.io.UnsupportedEncodingException ex) { - throw new RuntimeException(ex); - } - - final int length = bytes.length; - if (length > 1073741824) { - throw new IllegalArgumentException("length > max value for type: " + length); - } - - final int headerLength = 4; - final int limit = parentMessage.limit(); - parentMessage.limit(limit + headerLength + length); - buffer.putInt(limit, length, java.nio.ByteOrder.LITTLE_ENDIAN); - buffer.putBytes(limit + headerLength, bytes, 0, length); - - return this; - } - - public static int receivingChannelId() { - return 6; - } - - public static String receivingChannelCharacterEncoding() { - return "UTF-8"; - } - - public static String receivingChannelMetaAttribute(final MetaAttribute metaAttribute) { - switch (metaAttribute) { - case EPOCH: - return "unix"; - case TIME_UNIT: - return "nanosecond"; - case SEMANTIC_TYPE: - return ""; - } - - return ""; - } - - public static int receivingChannelHeaderLength() { - return 4; - } - - public ConnectEncoder putReceivingChannel( - final DirectBuffer src, final int srcOffset, final int length) { - if (length > 1073741824) { - throw new IllegalArgumentException("length > max value for type: " + length); - } - - final int headerLength = 4; - final int limit = parentMessage.limit(); - parentMessage.limit(limit + headerLength + length); - buffer.putInt(limit, length, java.nio.ByteOrder.LITTLE_ENDIAN); - buffer.putBytes(limit + headerLength, src, srcOffset, length); - - return this; - } - - public ConnectEncoder putReceivingChannel( - final byte[] src, final int srcOffset, final int length) { - if (length > 1073741824) { - throw new IllegalArgumentException("length > max value for type: " + length); - } - - final int headerLength = 4; - final int limit = parentMessage.limit(); - parentMessage.limit(limit + headerLength + length); - buffer.putInt(limit, length, java.nio.ByteOrder.LITTLE_ENDIAN); - buffer.putBytes(limit + headerLength, src, srcOffset, length); - - return this; - } - - public ConnectEncoder receivingChannel(final String value) { - final byte[] bytes; - try { - bytes = value.getBytes("UTF-8"); - } catch (final java.io.UnsupportedEncodingException ex) { - throw new RuntimeException(ex); - } - - final int length = bytes.length; - if (length > 1073741824) { - throw new IllegalArgumentException("length > max value for type: " + length); - } - - final int headerLength = 4; - final int limit = parentMessage.limit(); - parentMessage.limit(limit + headerLength + length); - buffer.putInt(limit, length, java.nio.ByteOrder.LITTLE_ENDIAN); - buffer.putBytes(limit + headerLength, bytes, 0, length); - - return this; - } - - public static int clientManagementChannelId() { - return 6; - } - - public static String clientManagementChannelCharacterEncoding() { - return "UTF-8"; - } - - public static String clientManagementChannelMetaAttribute(final MetaAttribute metaAttribute) { - switch (metaAttribute) { - case EPOCH: - return "unix"; - case TIME_UNIT: - return "nanosecond"; - case SEMANTIC_TYPE: - return ""; - } - - return ""; - } - - public static int clientManagementChannelHeaderLength() { - return 4; - } - - public ConnectEncoder putClientManagementChannel( - final DirectBuffer src, final int srcOffset, final int length) { - if (length > 1073741824) { - throw new IllegalArgumentException("length > max value for type: " + length); - } - - final int headerLength = 4; - final int limit = parentMessage.limit(); - parentMessage.limit(limit + headerLength + length); - buffer.putInt(limit, length, java.nio.ByteOrder.LITTLE_ENDIAN); - buffer.putBytes(limit + headerLength, src, srcOffset, length); - - return this; - } - - public ConnectEncoder putClientManagementChannel( - final byte[] src, final int srcOffset, final int length) { - if (length > 1073741824) { - throw new IllegalArgumentException("length > max value for type: " + length); - } - - final int headerLength = 4; - final int limit = parentMessage.limit(); - parentMessage.limit(limit + headerLength + length); - buffer.putInt(limit, length, java.nio.ByteOrder.LITTLE_ENDIAN); - buffer.putBytes(limit + headerLength, src, srcOffset, length); - - return this; - } - - public ConnectEncoder clientManagementChannel(final String value) { - final byte[] bytes; - try { - bytes = value.getBytes("UTF-8"); - } catch (final java.io.UnsupportedEncodingException ex) { - throw new RuntimeException(ex); - } - - final int length = bytes.length; - if (length > 1073741824) { - throw new IllegalArgumentException("length > max value for type: " + length); - } - - final int headerLength = 4; - final int limit = parentMessage.limit(); - parentMessage.limit(limit + headerLength + length); - buffer.putInt(limit, length, java.nio.ByteOrder.LITTLE_ENDIAN); - buffer.putBytes(limit + headerLength, bytes, 0, length); - - return this; - } - - public String toString() { - return appendTo(new StringBuilder(100)).toString(); - } - - public StringBuilder appendTo(final StringBuilder builder) { - ConnectDecoder writer = new ConnectDecoder(); - writer.wrap(buffer, offset, BLOCK_LENGTH, SCHEMA_VERSION); - - return writer.appendTo(builder); - } -} diff --git a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/messages/MessageHeaderDecoder.java b/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/messages/MessageHeaderDecoder.java deleted file mode 100644 index 2c3e6f464..000000000 --- a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/messages/MessageHeaderDecoder.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* Generated SBE (Simple Binary Encoding) message codec */ - -package io.rsocket.aeron.internal.reactivestreams.messages; - -import org.agrona.DirectBuffer; - -@javax.annotation.Generated( - value = {"io.rsocket.aeron.internal.reactivestreams.messages.MessageHeaderDecoder"} -) -@SuppressWarnings("all") -public class MessageHeaderDecoder { - public static final int ENCODED_LENGTH = 8; - private DirectBuffer buffer; - private int offset; - - public MessageHeaderDecoder wrap(final DirectBuffer buffer, final int offset) { - this.buffer = buffer; - this.offset = offset; - - return this; - } - - public int encodedLength() { - return ENCODED_LENGTH; - } - - public static int blockLengthNullValue() { - return 65535; - } - - public static int blockLengthMinValue() { - return 0; - } - - public static int blockLengthMaxValue() { - return 65534; - } - - public int blockLength() { - return (buffer.getShort(offset + 0, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF); - } - - public static int templateIdNullValue() { - return 65535; - } - - public static int templateIdMinValue() { - return 0; - } - - public static int templateIdMaxValue() { - return 65534; - } - - public int templateId() { - return (buffer.getShort(offset + 2, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF); - } - - public static int schemaIdNullValue() { - return 65535; - } - - public static int schemaIdMinValue() { - return 0; - } - - public static int schemaIdMaxValue() { - return 65534; - } - - public int schemaId() { - return (buffer.getShort(offset + 4, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF); - } - - public static int versionNullValue() { - return 65535; - } - - public static int versionMinValue() { - return 0; - } - - public static int versionMaxValue() { - return 65534; - } - - public int version() { - return (buffer.getShort(offset + 6, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF); - } -} diff --git a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/messages/MessageHeaderEncoder.java b/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/messages/MessageHeaderEncoder.java deleted file mode 100644 index 8bd1b58f6..000000000 --- a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/messages/MessageHeaderEncoder.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* Generated SBE (Simple Binary Encoding) message codec */ - -package io.rsocket.aeron.internal.reactivestreams.messages; - -import org.agrona.MutableDirectBuffer; - -@javax.annotation.Generated( - value = {"io.rsocket.aeron.internal.reactivestreams.messages.MessageHeaderEncoder"} -) -@SuppressWarnings("all") -public class MessageHeaderEncoder { - public static final int ENCODED_LENGTH = 8; - private MutableDirectBuffer buffer; - private int offset; - - public MessageHeaderEncoder wrap(final MutableDirectBuffer buffer, final int offset) { - this.buffer = buffer; - this.offset = offset; - - return this; - } - - public int encodedLength() { - return ENCODED_LENGTH; - } - - public static int blockLengthNullValue() { - return 65535; - } - - public static int blockLengthMinValue() { - return 0; - } - - public static int blockLengthMaxValue() { - return 65534; - } - - public MessageHeaderEncoder blockLength(final int value) { - buffer.putShort(offset + 0, (short) value, java.nio.ByteOrder.LITTLE_ENDIAN); - return this; - } - - public static int templateIdNullValue() { - return 65535; - } - - public static int templateIdMinValue() { - return 0; - } - - public static int templateIdMaxValue() { - return 65534; - } - - public MessageHeaderEncoder templateId(final int value) { - buffer.putShort(offset + 2, (short) value, java.nio.ByteOrder.LITTLE_ENDIAN); - return this; - } - - public static int schemaIdNullValue() { - return 65535; - } - - public static int schemaIdMinValue() { - return 0; - } - - public static int schemaIdMaxValue() { - return 65534; - } - - public MessageHeaderEncoder schemaId(final int value) { - buffer.putShort(offset + 4, (short) value, java.nio.ByteOrder.LITTLE_ENDIAN); - return this; - } - - public static int versionNullValue() { - return 65535; - } - - public static int versionMinValue() { - return 0; - } - - public static int versionMaxValue() { - return 65534; - } - - public MessageHeaderEncoder version(final int value) { - buffer.putShort(offset + 6, (short) value, java.nio.ByteOrder.LITTLE_ENDIAN); - return this; - } -} diff --git a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/messages/MetaAttribute.java b/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/messages/MetaAttribute.java deleted file mode 100644 index b4a0b5594..000000000 --- a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/messages/MetaAttribute.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* Generated SBE (Simple Binary Encoding) message codec */ - -package io.rsocket.aeron.internal.reactivestreams.messages; - -@javax.annotation.Generated( - value = {"io.rsocket.aeron.internal.reactivestreams.messages.MetaAttribute"} -) -public enum MetaAttribute { - EPOCH, - TIME_UNIT, - SEMANTIC_TYPE -} diff --git a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/messages/VarDataEncodingDecoder.java b/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/messages/VarDataEncodingDecoder.java deleted file mode 100644 index cea04b1e7..000000000 --- a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/messages/VarDataEncodingDecoder.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* Generated SBE (Simple Binary Encoding) message codec */ - -package io.rsocket.aeron.internal.reactivestreams.messages; - -import org.agrona.DirectBuffer; - -@javax.annotation.Generated( - value = {"io.rsocket.aeron.internal.reactivestreams.messages.VarDataEncodingDecoder"} -) -@SuppressWarnings("all") -public class VarDataEncodingDecoder { - public static final int ENCODED_LENGTH = -1; - private DirectBuffer buffer; - private int offset; - - public VarDataEncodingDecoder wrap(final DirectBuffer buffer, final int offset) { - this.buffer = buffer; - this.offset = offset; - - return this; - } - - public int encodedLength() { - return ENCODED_LENGTH; - } - - public static long lengthNullValue() { - return 4294967294L; - } - - public static long lengthMinValue() { - return 0L; - } - - public static long lengthMaxValue() { - return 1073741824L; - } - - public long length() { - return (buffer.getInt(offset + 0, java.nio.ByteOrder.LITTLE_ENDIAN) & 0xFFFF_FFFFL); - } - - public static short varDataNullValue() { - return (short) 255; - } - - public static short varDataMinValue() { - return (short) 0; - } - - public static short varDataMaxValue() { - return (short) 254; - } - - public String toString() { - return appendTo(new StringBuilder(100)).toString(); - } - - public StringBuilder appendTo(final StringBuilder builder) { - builder.append('('); - // Token{signal=ENCODING, name='length', description='The channel the client listens for - // management data on', id=-1, version=0, encodedLength=4, offset=0, componentTokenCount=1, - // encoding=Encoding{presence=REQUIRED, primitiveType=UINT32, byteOrder=LITTLE_ENDIAN, - // minValue=null, maxValue=1073741824, nullValue=null, constValue=null, - // characterEncoding='UTF-8', epoch='unix', timeUnit=nanosecond, semanticType='null'}} - builder.append("length="); - builder.append(length()); - builder.append('|'); - // Token{signal=ENCODING, name='varData', description='The channel the client listens for - // management data on', id=-1, version=0, encodedLength=-1, offset=4, componentTokenCount=1, - // encoding=Encoding{presence=REQUIRED, primitiveType=UINT8, byteOrder=LITTLE_ENDIAN, - // minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='UTF-8', - // epoch='unix', timeUnit=nanosecond, semanticType='null'}} - builder.append(')'); - - return builder; - } -} diff --git a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/messages/VarDataEncodingEncoder.java b/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/messages/VarDataEncodingEncoder.java deleted file mode 100644 index ab23e24a1..000000000 --- a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/internal/reactivestreams/messages/VarDataEncodingEncoder.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* Generated SBE (Simple Binary Encoding) message codec */ - -package io.rsocket.aeron.internal.reactivestreams.messages; - -import org.agrona.MutableDirectBuffer; - -@javax.annotation.Generated( - value = {"io.rsocket.aeron.internal.reactivestreams.messages.VarDataEncodingEncoder"} -) -@SuppressWarnings("all") -public class VarDataEncodingEncoder { - public static final int ENCODED_LENGTH = -1; - private MutableDirectBuffer buffer; - private int offset; - - public VarDataEncodingEncoder wrap(final MutableDirectBuffer buffer, final int offset) { - this.buffer = buffer; - this.offset = offset; - - return this; - } - - public int encodedLength() { - return ENCODED_LENGTH; - } - - public static long lengthNullValue() { - return 4294967294L; - } - - public static long lengthMinValue() { - return 0L; - } - - public static long lengthMaxValue() { - return 1073741824L; - } - - public VarDataEncodingEncoder length(final long value) { - buffer.putInt(offset + 0, (int) value, java.nio.ByteOrder.LITTLE_ENDIAN); - return this; - } - - public static short varDataNullValue() { - return (short) 255; - } - - public static short varDataMinValue() { - return (short) 0; - } - - public static short varDataMaxValue() { - return (short) 254; - } - - public String toString() { - return appendTo(new StringBuilder(100)).toString(); - } - - public StringBuilder appendTo(final StringBuilder builder) { - VarDataEncodingDecoder writer = new VarDataEncodingDecoder(); - writer.wrap(buffer, offset); - - return writer.appendTo(builder); - } -} diff --git a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/server/AeronServerTransport.java b/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/server/AeronServerTransport.java deleted file mode 100644 index 1a0429c7d..000000000 --- a/rsocket-transport-aeron/src/main/java/io/rsocket/aeron/server/AeronServerTransport.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.rsocket.aeron.server; - -import io.rsocket.Closeable; -import io.rsocket.DuplexConnection; -import io.rsocket.aeron.AeronDuplexConnection; -import io.rsocket.aeron.internal.AeronWrapper; -import io.rsocket.aeron.internal.EventLoop; -import io.rsocket.aeron.internal.reactivestreams.AeronChannelServer; -import io.rsocket.aeron.internal.reactivestreams.AeronSocketAddress; -import io.rsocket.transport.ServerTransport; -import reactor.core.publisher.Mono; - -/** */ -public class AeronServerTransport implements ServerTransport { - private final AeronWrapper aeronWrapper; - private final AeronSocketAddress managementSubscriptionSocket; - private final EventLoop eventLoop; - - private AeronChannelServer aeronChannelServer; - - public AeronServerTransport( - AeronWrapper aeronWrapper, - AeronSocketAddress managementSubscriptionSocket, - EventLoop eventLoop) { - this.aeronWrapper = aeronWrapper; - this.managementSubscriptionSocket = managementSubscriptionSocket; - this.eventLoop = eventLoop; - } - - @Override - public Mono start(ConnectionAcceptor acceptor) { - synchronized (this) { - if (aeronChannelServer != null) { - throw new IllegalStateException("server already ready started"); - } - - aeronChannelServer = - AeronChannelServer.create( - aeronChannel -> { - DuplexConnection connection = new AeronDuplexConnection("server", aeronChannel); - acceptor.apply(connection).subscribe(); - }, - aeronWrapper, - managementSubscriptionSocket, - eventLoop); - } - - return Mono.just(aeronChannelServer.start()); - } -} diff --git a/rsocket-transport-aeron/src/main/resources/META-INF/services/io.rsocket.uri.UriHandler b/rsocket-transport-aeron/src/main/resources/META-INF/services/io.rsocket.uri.UriHandler deleted file mode 100644 index 84db6fd4a..000000000 --- a/rsocket-transport-aeron/src/main/resources/META-INF/services/io.rsocket.uri.UriHandler +++ /dev/null @@ -1,17 +0,0 @@ -# -# Copyright 2015-2018 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -io.rsocket.aeron.AeronUriHandler diff --git a/rsocket-transport-aeron/src/main/resources/aeron-channel-schema.xml b/rsocket-transport-aeron/src/main/resources/aeron-channel-schema.xml deleted file mode 100644 index cbd64809f..000000000 --- a/rsocket-transport-aeron/src/main/resources/aeron-channel-schema.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/rsocket-transport-aeron/src/test/java/io/rsocket/aeron/AeronClientSetupRule.java b/rsocket-transport-aeron/src/test/java/io/rsocket/aeron/AeronClientSetupRule.java deleted file mode 100644 index 4a7cdc6ae..000000000 --- a/rsocket-transport-aeron/src/test/java/io/rsocket/aeron/AeronClientSetupRule.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.rsocket.aeron; - -import io.rsocket.Closeable; -import io.rsocket.aeron.client.AeronClientTransport; -import io.rsocket.aeron.internal.*; -import io.rsocket.aeron.internal.reactivestreams.AeronClientChannelConnector; -import io.rsocket.aeron.internal.reactivestreams.AeronSocketAddress; -import io.rsocket.aeron.server.AeronServerTransport; -import io.rsocket.test.ClientSetupRule; - -class AeronClientSetupRule extends ClientSetupRule { - - public static final AeronSocketAddress ADDRESS = - AeronSocketAddress.create("aeron:udp", "127.0.0.1", 39790); - - static { - MediaDriverHolder.getInstance(); - AeronWrapper aeronWrapper = new DefaultAeronWrapper(); - - EventLoop serverEventLoop = new SingleThreadedEventLoop("server"); - server = new AeronServerTransport(aeronWrapper, ADDRESS, serverEventLoop); - - // Create Client Connector - EventLoop clientEventLoop = new SingleThreadedEventLoop("client"); - - AeronClientChannelConnector.AeronClientConfig config = - AeronClientChannelConnector.AeronClientConfig.create( - ADDRESS, - ADDRESS, - Constants.CLIENT_STREAM_ID, - Constants.SERVER_STREAM_ID, - clientEventLoop); - - AeronClientChannelConnector connector = - AeronClientChannelConnector.create(aeronWrapper, ADDRESS, clientEventLoop); - - client = new AeronClientTransport(connector, config); - } - - private static final AeronServerTransport server; - private static final AeronClientTransport client; - - AeronClientSetupRule() { - super(() -> ADDRESS, (address, server) -> client, address -> server); - } -} diff --git a/rsocket-transport-aeron/src/test/java/io/rsocket/aeron/AeronPing.java b/rsocket-transport-aeron/src/test/java/io/rsocket/aeron/AeronPing.java deleted file mode 100644 index 15db974c7..000000000 --- a/rsocket-transport-aeron/src/test/java/io/rsocket/aeron/AeronPing.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.rsocket.aeron; - -import io.rsocket.RSocket; -import io.rsocket.RSocketFactory; -import io.rsocket.aeron.client.AeronClientTransport; -import io.rsocket.aeron.internal.*; -import io.rsocket.aeron.internal.reactivestreams.AeronClientChannelConnector; -import io.rsocket.aeron.internal.reactivestreams.AeronSocketAddress; -import io.rsocket.test.PingClient; -import java.time.Duration; -import org.HdrHistogram.Recorder; -import reactor.core.publisher.Mono; - -public final class AeronPing { - - public static void main(String... args) { - // Create Client Connector - AeronWrapper aeronWrapper = new DefaultAeronWrapper(); - - AeronSocketAddress clientManagementSocketAddress = - AeronSocketAddress.create("aeron:udp", "127.0.0.1", 39790); - EventLoop clientEventLoop = new SingleThreadedEventLoop("client"); - - AeronSocketAddress receiveAddress = AeronSocketAddress.create("aeron:udp", "127.0.0.1", 39790); - AeronSocketAddress sendAddress = AeronSocketAddress.create("aeron:udp", "127.0.0.1", 39790); - - AeronClientChannelConnector.AeronClientConfig config = - AeronClientChannelConnector.AeronClientConfig.create( - receiveAddress, - sendAddress, - Constants.CLIENT_STREAM_ID, - Constants.SERVER_STREAM_ID, - clientEventLoop); - - AeronClientChannelConnector connector = - AeronClientChannelConnector.create( - aeronWrapper, clientManagementSocketAddress, clientEventLoop); - - AeronClientTransport aeronTransportClient = new AeronClientTransport(connector, config); - - Mono client = RSocketFactory.connect().transport(aeronTransportClient).start(); - PingClient pingClient = new PingClient(client); - Recorder recorder = pingClient.startTracker(Duration.ofSeconds(1)); - final int count = 1_000_000_000; - pingClient - .startPingPong(count, recorder) - .doOnTerminate(() -> System.out.println("Sent " + count + " messages.")) - .blockLast(); - - System.exit(0); - } -} diff --git a/rsocket-transport-aeron/src/test/java/io/rsocket/aeron/AeronPongServer.java b/rsocket-transport-aeron/src/test/java/io/rsocket/aeron/AeronPongServer.java deleted file mode 100644 index 28b9080c4..000000000 --- a/rsocket-transport-aeron/src/test/java/io/rsocket/aeron/AeronPongServer.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.rsocket.aeron; - -import io.aeron.driver.MediaDriver; -import io.aeron.driver.ThreadingMode; -import io.rsocket.RSocketFactory; -import io.rsocket.aeron.internal.AeronWrapper; -import io.rsocket.aeron.internal.DefaultAeronWrapper; -import io.rsocket.aeron.internal.EventLoop; -import io.rsocket.aeron.internal.SingleThreadedEventLoop; -import io.rsocket.aeron.internal.reactivestreams.AeronSocketAddress; -import io.rsocket.aeron.server.AeronServerTransport; -import io.rsocket.test.PingHandler; - -public final class AeronPongServer { - static { - final io.aeron.driver.MediaDriver.Context ctx = - new io.aeron.driver.MediaDriver.Context() - .threadingMode(ThreadingMode.SHARED_NETWORK) - .dirDeleteOnStart(true); - MediaDriver.launch(ctx); - } - - public static void main(String... args) { - MediaDriverHolder.getInstance(); - AeronWrapper aeronWrapper = new DefaultAeronWrapper(); - - AeronSocketAddress serverManagementSocketAddress = - AeronSocketAddress.create("aeron:udp", "127.0.0.1", 39790); - EventLoop serverEventLoop = new SingleThreadedEventLoop("server"); - AeronServerTransport server = - new AeronServerTransport(aeronWrapper, serverManagementSocketAddress, serverEventLoop); - - AeronServerTransport transport = - new AeronServerTransport(aeronWrapper, serverManagementSocketAddress, serverEventLoop); - RSocketFactory.receive().acceptor(new PingHandler()).transport(transport).start(); - } -} diff --git a/rsocket-transport-aeron/src/test/java/io/rsocket/aeron/ClientServerTest.java b/rsocket-transport-aeron/src/test/java/io/rsocket/aeron/ClientServerTest.java deleted file mode 100644 index c34b6d4df..000000000 --- a/rsocket-transport-aeron/src/test/java/io/rsocket/aeron/ClientServerTest.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.rsocket.aeron; - -import static org.junit.Assert.assertEquals; - -import io.rsocket.Payload; -import io.rsocket.test.ClientSetupRule; -import io.rsocket.util.DefaultPayload; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import reactor.core.publisher.Flux; - -@Ignore -public class ClientServerTest { - - @Rule public final ClientSetupRule setup = new AeronClientSetupRule(); - - @Test(timeout = 10000) - public void testFireNForget10() { - long outputCount = - Flux.range(1, 10) - .flatMap( - i -> setup.getRSocket().fireAndForget(DefaultPayload.create("hello", "metadata"))) - .doOnError(Throwable::printStackTrace) - .count() - .block(); - - assertEquals(0, outputCount); - } - - @Test(timeout = 10000) - public void testPushMetadata10() { - long outputCount = - Flux.range(1, 10) - .flatMap(i -> setup.getRSocket().metadataPush(DefaultPayload.create("", "metadata"))) - .doOnError(Throwable::printStackTrace) - .count() - .block(); - - assertEquals(0, outputCount); - } - - @Test(timeout = 5000000) - public void testRequestResponse1() { - long outputCount = - Flux.range(1, 1) - .flatMap( - i -> - setup - .getRSocket() - .requestResponse(DefaultPayload.create("hello", "metadata")) - .map(Payload::getDataUtf8)) - .doOnError(Throwable::printStackTrace) - .count() - .block(); - - assertEquals(1, outputCount); - } - - @Test(timeout = 2000) - public void testRequestResponse10() { - long outputCount = - Flux.range(1, 10) - .flatMap( - i -> - setup - .getRSocket() - .requestResponse(DefaultPayload.create("hello", "metadata")) - .map(Payload::getDataUtf8)) - .doOnError(Throwable::printStackTrace) - .count() - .block(); - - assertEquals(10, outputCount); - } - - @Test(timeout = 2000) - public void testRequestResponse100() { - long outputCount = - Flux.range(1, 100) - .flatMap( - i -> - setup - .getRSocket() - .requestResponse(DefaultPayload.create("hello", "metadata")) - .map(Payload::getDataUtf8)) - .doOnError(Throwable::printStackTrace) - .count() - .block(); - - assertEquals(100, outputCount); - } - - @Test(timeout = 5000) - public void testRequestResponse10_000() { - long outputCount = - Flux.range(1, 10_000) - .flatMap( - i -> - setup - .getRSocket() - .requestResponse(DefaultPayload.create("hello", "metadata")) - .map(Payload::getDataUtf8)) - .doOnError(Throwable::printStackTrace) - .count() - .block(); - - assertEquals(10_000, outputCount); - } - - @Test(timeout = 10000) - public void testRequestStream() { - Flux publisher = - setup.getRSocket().requestStream(DefaultPayload.create("hello", "metadata")); - - long count = publisher.take(5).count().block(); - - assertEquals(5, count); - } -} diff --git a/rsocket-transport-aeron/src/test/java/io/rsocket/aeron/MediaDriverHolder.java b/rsocket-transport-aeron/src/test/java/io/rsocket/aeron/MediaDriverHolder.java deleted file mode 100644 index d43768c28..000000000 --- a/rsocket-transport-aeron/src/test/java/io/rsocket/aeron/MediaDriverHolder.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.rsocket.aeron; - -import io.aeron.driver.MediaDriver; -import io.aeron.driver.ThreadingMode; -import java.util.concurrent.TimeUnit; -import org.agrona.concurrent.SleepingIdleStrategy; - -public class MediaDriverHolder { - private static final MediaDriverHolder INSTANCE = new MediaDriverHolder(); - - static { - final io.aeron.driver.MediaDriver.Context ctx = - new io.aeron.driver.MediaDriver.Context() - .threadingMode(ThreadingMode.SHARED) - .dirDeleteOnStart(true) - .conductorIdleStrategy(new SleepingIdleStrategy(TimeUnit.MILLISECONDS.toNanos(1))) - .receiverIdleStrategy(new SleepingIdleStrategy(TimeUnit.MILLISECONDS.toNanos(1))) - .senderIdleStrategy(new SleepingIdleStrategy(TimeUnit.MILLISECONDS.toNanos(1))); - - ctx.driverTimeoutMs(TimeUnit.MINUTES.toMillis(10)); - MediaDriver.launch(ctx); - } - - private MediaDriverHolder() {} - - public static MediaDriverHolder getInstance() { - return INSTANCE; - } -} diff --git a/rsocket-transport-aeron/src/test/java/io/rsocket/aeron/internal/reactivestreams/AeronChannelPing.java b/rsocket-transport-aeron/src/test/java/io/rsocket/aeron/internal/reactivestreams/AeronChannelPing.java deleted file mode 100644 index af62c46c7..000000000 --- a/rsocket-transport-aeron/src/test/java/io/rsocket/aeron/internal/reactivestreams/AeronChannelPing.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.rsocket.aeron.internal.reactivestreams; - -import io.rsocket.aeron.internal.AeronWrapper; -import io.rsocket.aeron.internal.DefaultAeronWrapper; -import io.rsocket.aeron.internal.SingleThreadedEventLoop; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicLong; -import org.HdrHistogram.Recorder; -import org.agrona.concurrent.UnsafeBuffer; -import reactor.core.publisher.Flux; - -/** */ -public final class AeronChannelPing { - public static void main(String... args) { - int count = 1_000_000_000; - final Recorder histogram = new Recorder(Long.MAX_VALUE, 3); - Executors.newSingleThreadScheduledExecutor() - .scheduleAtFixedRate( - () -> { - System.out.println("---- PING/ PONG HISTO ----"); - histogram - .getIntervalHistogram() - .outputPercentileDistribution(System.out, 5, 1000.0, false); - System.out.println("---- PING/ PONG HISTO ----"); - }, - 1, - 1, - TimeUnit.SECONDS); - - AeronWrapper wrapper = new DefaultAeronWrapper(); - AeronSocketAddress managementSocketAddress = - AeronSocketAddress.create("aeron:udp", "127.0.0.1", 39790); - SingleThreadedEventLoop eventLoop = new SingleThreadedEventLoop("client"); - AeronClientChannelConnector connector = - AeronClientChannelConnector.create(wrapper, managementSocketAddress, eventLoop); - - AeronSocketAddress receiveAddress = AeronSocketAddress.create("aeron:udp", "127.0.0.1", 39790); - AeronSocketAddress sendAddress = AeronSocketAddress.create("aeron:udp", "127.0.0.1", 39790); - - AeronClientChannelConnector.AeronClientConfig config = - AeronClientChannelConnector.AeronClientConfig.create( - receiveAddress, sendAddress, 1, 2, eventLoop); - - AeronChannel channel = connector.apply(config).block(); - - AtomicLong lastUpdate = new AtomicLong(System.nanoTime()); - channel - .receive() - .doOnNext( - b -> { - synchronized (wrapper) { - int anInt = b.getInt(0); - if (anInt % 1_000 == 0) { - long diff = System.nanoTime() - lastUpdate.get(); - histogram.recordValue(diff); - lastUpdate.set(System.nanoTime()); - } - } - }) - .doOnError(Throwable::printStackTrace) - .subscribe(); - - byte[] b = new byte[1024]; - Flux.range(0, count) - .flatMap( - i -> { - UnsafeBuffer buffer = new UnsafeBuffer(b); - buffer.putInt(0, i); - return channel.send(buffer); - }, - 8) - .last(null) - .block(); - } -} diff --git a/rsocket-transport-aeron/src/test/java/io/rsocket/aeron/internal/reactivestreams/AeronChannelPongServer.java b/rsocket-transport-aeron/src/test/java/io/rsocket/aeron/internal/reactivestreams/AeronChannelPongServer.java deleted file mode 100644 index aa0296c45..000000000 --- a/rsocket-transport-aeron/src/test/java/io/rsocket/aeron/internal/reactivestreams/AeronChannelPongServer.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.rsocket.aeron.internal.reactivestreams; - -import io.rsocket.aeron.MediaDriverHolder; -import io.rsocket.aeron.internal.AeronWrapper; -import io.rsocket.aeron.internal.DefaultAeronWrapper; -import io.rsocket.aeron.internal.SingleThreadedEventLoop; -import org.agrona.DirectBuffer; -import reactor.core.publisher.Flux; - -/** */ -public class AeronChannelPongServer { - public static void main(String... args) { - MediaDriverHolder.getInstance(); - AeronWrapper wrapper = new DefaultAeronWrapper(); - AeronSocketAddress managementSubscription = - AeronSocketAddress.create("aeron:udp", "127.0.0.1", 39790); - SingleThreadedEventLoop eventLoop = new SingleThreadedEventLoop("server"); - - AeronChannelServer.AeronChannelConsumer consumer = - aeronChannel -> { - Flux receive = aeronChannel.receive(); - // .doOnNext(b -> System.out.println("server got => " + b.getInt(0))); - - aeronChannel.send(receive).doOnError(Throwable::printStackTrace).subscribe(); - }; - - AeronChannelServer server = - AeronChannelServer.create(consumer, wrapper, managementSubscription, eventLoop); - AeronChannelServer.AeronChannelStartedServer start = server.start(); - start.awaitShutdown(); - } -} diff --git a/rsocket-transport-aeron/src/test/java/io/rsocket/aeron/internal/reactivestreams/AeronChannelTest.java b/rsocket-transport-aeron/src/test/java/io/rsocket/aeron/internal/reactivestreams/AeronChannelTest.java deleted file mode 100644 index 2a5339af2..000000000 --- a/rsocket-transport-aeron/src/test/java/io/rsocket/aeron/internal/reactivestreams/AeronChannelTest.java +++ /dev/null @@ -1,342 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.rsocket.aeron.internal.reactivestreams; - -import io.aeron.Aeron; -import io.aeron.Publication; -import io.aeron.Subscription; -import io.rsocket.aeron.MediaDriverHolder; -import io.rsocket.aeron.internal.Constants; -import io.rsocket.aeron.internal.EventLoop; -import io.rsocket.aeron.internal.SingleThreadedEventLoop; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ThreadLocalRandom; -import org.agrona.BitUtil; -import org.agrona.LangUtil; -import org.agrona.concurrent.UnsafeBuffer; -import org.junit.Ignore; -import org.junit.Test; -import reactor.core.publisher.Flux; - -/** */ -@Ignore("travis does not like me") -public class AeronChannelTest { - static { - // System.setProperty("aeron.publication.linger.timeout", String.valueOf(50_000_000_000L)); - // System.setProperty("aeron.client.liveness.timeout", String.valueOf(50_000_000_000L)); - MediaDriverHolder.getInstance(); - } - - @Test - @Ignore - public void testPing() { - - int count = 5_000_000; - CountDownLatch countDownLatch = new CountDownLatch(count); - - CountDownLatch sync = new CountDownLatch(2); - Aeron.Context ctx = new Aeron.Context(); - - // ctx.publicationConnectionTimeout(TimeUnit.MINUTES.toNanos(5)); - - ctx.availableImageHandler( - image -> { - System.out.println( - "name image subscription => " - + image.subscription().channel() - + " streamId => " - + image.subscription().streamId() - + " registrationId => " - + image.subscription().registrationId()); - sync.countDown(); - }); - - ctx.unavailableImageHandler( - image -> - System.out.println( - "=== unavailable image name image subscription => " - + image.subscription().channel() - + " streamId => " - + image.subscription().streamId() - + " registrationId => " - + image.subscription().registrationId())); - /*ctx.errorHandler(t -> { - /* StringWriter writer = new StringWriter(); - PrintWriter w = new PrintWriter(writer); - t.printStackTrace(w); - - w.flush();* - - // System.out.println("\nGOT AERON ERROR => \n [" + writer.toString() + "]\n\n"); - });*/ - - ctx.driverTimeoutMs(Integer.MAX_VALUE); - Aeron aeron = Aeron.connect(ctx); - /* - Subscription serverSubscription = aeron.addSubscription("aeron:ipc", Constants.SERVER_STREAM_ID); - Publication serverPublication = aeron.addPublication("aeron:ipc", Constants.CLIENT_STREAM_ID); - - Subscription clientSubscription = aeron.addSubscription("aeron:ipc", Constants.CLIENT_STREAM_ID); - Publication clientPublication = aeron.addPublication("aeron:ipc", Constants.SERVER_STREAM_ID); - */ - - Subscription serverSubscription = - aeron.addSubscription("aeron:udp?endpoint=localhost:39791", Constants.SERVER_STREAM_ID); - System.out.println( - "serverSubscription registration id => " + serverSubscription.registrationId()); - - Publication serverPublication = - aeron.addPublication("aeron:udp?endpoint=localhost:39790", Constants.CLIENT_STREAM_ID); - - Subscription clientSubscription = - aeron.addSubscription("aeron:udp?endpoint=localhost:39790", Constants.CLIENT_STREAM_ID); - - System.out.println( - "clientSubscription registration id => " + clientSubscription.registrationId()); - Publication clientPublication = - aeron.addPublication("aeron:udp?endpoint=localhost:39791", Constants.SERVER_STREAM_ID); - - try { - sync.await(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - - EventLoop serverLoop = new SingleThreadedEventLoop("server"); - - AeronOutPublisher publisher = - new AeronOutPublisher( - "server", clientPublication.sessionId(), serverSubscription, serverLoop); - publisher - .doOnNext(i -> countDownLatch.countDown()) - .doOnError(Throwable::printStackTrace) - .subscribe(); - - AeronInSubscriber aeronInSubscriber = new AeronInSubscriber("client", clientPublication); - - Flux unsafeBufferObservable = - Flux.range(1, count) - // .doOnNext(i -> LockSupport.parkNanos(TimeUnit.MICROSECONDS.toNanos(50))) - // .doOnNext(i -> System.out.println(Thread.currentThread() + " => client sending => " + - // i)) - .map( - i -> { - UnsafeBuffer buffer = new UnsafeBuffer(new byte[BitUtil.SIZE_OF_INT]); - buffer.putInt(0, i); - return buffer; - }) - // .doOnRequest(l -> System.out.println("Client reuqested => " + l)) - .doOnError(Throwable::printStackTrace) - .doOnComplete(() -> System.out.println("Im done")); - - unsafeBufferObservable.subscribe(aeronInSubscriber); - - try { - countDownLatch.await(); - } catch (InterruptedException e) { - LangUtil.rethrowUnchecked(e); - } - System.out.println("HERE!!!!"); - } - - @Test(timeout = 2_000) - public void testPingPong_10() { - pingPong(10); - } - - @Test(timeout = 2_000) - public void testPingPong_100() { - pingPong(100); - } - - @Test(timeout = 5_000) - public void testPingPong_300() { - pingPong(300); - } - - @Test(timeout = 5_000) - public void testPingPong_1_000() { - pingPong(1_000); - } - - @Test(timeout = 15_000) - public void testPingPong_10_000() { - pingPong(10_000); - } - - @Ignore - @Test(timeout = 5_000) - public void testPingPong_100_000() { - pingPong(100_000); - } - - @Ignore - @Test(timeout = 15_000) - public void testPingPong_1_000_000() { - pingPong(1_000_000); - } - - @Test(timeout = 50_000) - @Ignore - public void testPingPong_10_000_000() { - pingPong(10_000_000); - } - - @Test - @Ignore - public void testPingPongAlot() { - pingPong(100_000_000); - } - - private void pingPong(int count) { - - CountDownLatch sync = new CountDownLatch(2); - Aeron.Context ctx = new Aeron.Context(); - ctx.availableImageHandler( - image -> { - System.out.println( - "name image subscription => " - + image.subscription().channel() - + " streamId => " - + image.subscription().streamId() - + " registrationId => " - + image.subscription().registrationId()); - sync.countDown(); - }); - - ctx.unavailableImageHandler( - image -> - System.out.println( - "=== unavailable image name image subscription => " - + image.subscription().channel() - + " streamId => " - + image.subscription().streamId() - + " registrationId => " - + image.subscription().registrationId())); - - /*ctx.errorHandler(t -> { - /* StringWriter writer = new StringWriter(); - PrintWriter w = new PrintWriter(writer); - t.printStackTrace(w); - - w.flush();* - - // System.out.println("\nGOT AERON ERROR => \n [" + writer.toString() + "]\n\n"); - });*/ - - // ctx.driverTimeoutMs(Integer.MAX_VALUE); - Aeron aeron = Aeron.connect(ctx); - - Subscription serverSubscription = - aeron.addSubscription("aeron:ipc", Constants.SERVER_STREAM_ID); - Publication serverPublication = aeron.addPublication("aeron:ipc", Constants.CLIENT_STREAM_ID); - - Subscription clientSubscription = - aeron.addSubscription("aeron:ipc", Constants.CLIENT_STREAM_ID); - Publication clientPublication = aeron.addPublication("aeron:ipc", Constants.SERVER_STREAM_ID); - - /* - Subscription serverSubscription = aeron.addSubscription("udp://localhost:39791", Constants.SERVER_STREAM_ID); - System.out.println("serverSubscription registration id => " + serverSubscription.registrationId()); - - Publication serverPublication = aeron.addPublication("udp://localhost:39790", Constants.CLIENT_STREAM_ID); - - Subscription clientSubscription = aeron.addSubscription("udp://localhost:39790", Constants.CLIENT_STREAM_ID); - - System.out.println("clientSubscription registration id => " + clientSubscription.registrationId()); - Publication clientPublication = aeron.addPublication("udp://localhost:39791", Constants.SERVER_STREAM_ID); - */ - try { - sync.await(); - } catch (InterruptedException e) { - LangUtil.rethrowUnchecked(e); - } - - SingleThreadedEventLoop serverLoop = new SingleThreadedEventLoop("server"); - SingleThreadedEventLoop clientLoop = new SingleThreadedEventLoop("client"); - - AeronChannel serverChannel = - new AeronChannel( - "server", - serverPublication, - serverSubscription, - serverLoop, - clientPublication.sessionId()); - - System.out.println("created server channel"); - - CountDownLatch latch = new CountDownLatch(count); - - serverChannel - .receive() - // latch.countDown(); - // System.out.println("received -> " + f.getInt(0)); - .flatMap(serverChannel::send, 32) - .doOnError(Throwable::printStackTrace) - .subscribe(); - - AeronChannel clientChannel = - new AeronChannel( - "client", - clientPublication, - clientSubscription, - clientLoop, - serverPublication.sessionId()); - - clientChannel - .receive() - .doOnNext( - l -> { - synchronized (latch) { - latch.countDown(); - if (latch.getCount() % 10_000 == 0) { - System.out.println("mod of client got back -> " + latch.getCount()); - } - // if (latch.getCount() < 10_000) { - // System.out.println("client got back -> " + latch.getCount()); - // } - } - }) - .doOnError(Throwable::printStackTrace) - .subscribe(); - - byte[] bytes = new byte[8]; - ThreadLocalRandom.current().nextBytes(bytes); - - Flux.range(1, count) - // .doOnRequest(l -> System.out.println("requested => " + l)) - .flatMap( - i -> { - // System.out.println("Sending -> " + i); - - // UnsafeBuffer b = new UnsafeBuffer(new byte[BitUtil.SIZE_OF_INT]); - UnsafeBuffer b = new UnsafeBuffer(bytes); - b.putInt(0, i); - - return clientChannel.send(b); - }, - 8) - .doOnError(Throwable::printStackTrace) - .subscribe(); - - try { - latch.await(); - } catch (Exception t) { - LangUtil.rethrowUnchecked(t); - } - } -} diff --git a/rsocket-transport-aeron/src/test/java/io/rsocket/aeron/internal/reactivestreams/AeronClientServerChannelTest.java b/rsocket-transport-aeron/src/test/java/io/rsocket/aeron/internal/reactivestreams/AeronClientServerChannelTest.java deleted file mode 100644 index 1874281d5..000000000 --- a/rsocket-transport-aeron/src/test/java/io/rsocket/aeron/internal/reactivestreams/AeronClientServerChannelTest.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.rsocket.aeron.internal.reactivestreams; - -import io.rsocket.aeron.MediaDriverHolder; -import io.rsocket.aeron.internal.AeronWrapper; -import io.rsocket.aeron.internal.DefaultAeronWrapper; -import io.rsocket.aeron.internal.EventLoop; -import io.rsocket.aeron.internal.SingleThreadedEventLoop; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ThreadLocalRandom; -import org.agrona.BitUtil; -import org.agrona.DirectBuffer; -import org.agrona.concurrent.UnsafeBuffer; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; -import org.reactivestreams.Publisher; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - -/** */ -@Ignore("travis does not like me") -public class AeronClientServerChannelTest { - static { - MediaDriverHolder.getInstance(); - } - - @Test(timeout = 5_000) - public void testConnect() throws Exception { - int clientId = ThreadLocalRandom.current().nextInt(0, 1_000); - int serverId = clientId + 1; - - System.out.println("test client stream id => " + clientId); - System.out.println("test server stream id => " + serverId); - - AeronWrapper aeronWrapper = new DefaultAeronWrapper(); - - // Create Client Connector - AeronSocketAddress clientManagementSocketAddress = - AeronSocketAddress.create("aeron:udp", "127.0.0.1", 39790); - EventLoop clientEventLoop = new SingleThreadedEventLoop("client"); - - AeronSocketAddress receiveAddress = AeronSocketAddress.create("aeron:udp", "127.0.0.1", 39790); - AeronSocketAddress sendAddress = AeronSocketAddress.create("aeron:udp", "127.0.0.1", 39790); - - AeronClientChannelConnector.AeronClientConfig config = - AeronClientChannelConnector.AeronClientConfig.create( - receiveAddress, sendAddress, clientId, serverId, clientEventLoop); - - AeronClientChannelConnector connector = - AeronClientChannelConnector.create( - aeronWrapper, clientManagementSocketAddress, clientEventLoop); - - // Create Server - CountDownLatch latch = new CountDownLatch(2); - - AeronChannelServer.AeronChannelConsumer consumer = - (AeronChannel aeronChannel) -> { - Assert.assertNotNull(aeronChannel); - latch.countDown(); - }; - - AeronSocketAddress serverManagementSocketAddress = - AeronSocketAddress.create("aeron:udp", "127.0.0.1", 39790); - EventLoop serverEventLoop = new SingleThreadedEventLoop("server"); - AeronChannelServer aeronChannelServer = - AeronChannelServer.create( - consumer, aeronWrapper, serverManagementSocketAddress, serverEventLoop); - - aeronChannelServer.start(); - - Publisher publisher = connector.apply(config); - Flux.from(publisher) - .doOnNext(Assert::assertNotNull) - .doOnNext(c -> latch.countDown()) - .doOnError( - t -> { - throw new RuntimeException(t); - }) - .subscribe(); - - latch.await(); - } - - @Test(timeout = 5_000) - public void testPingPong() throws Exception { - int clientId = ThreadLocalRandom.current().nextInt(2_000, 3_000); - int serverId = clientId + 1; - - System.out.println("test client stream id => " + clientId); - System.out.println("test server stream id => " + serverId); - - AeronWrapper aeronWrapper = new DefaultAeronWrapper(); - - // Create Client Connector - AeronSocketAddress clientManagementSocketAddress = - AeronSocketAddress.create("aeron:udp", "127.0.0.1", 39790); - EventLoop clientEventLoop = new SingleThreadedEventLoop("client"); - - AeronSocketAddress receiveAddress = AeronSocketAddress.create("aeron:udp", "127.0.0.1", 39790); - AeronSocketAddress sendAddress = AeronSocketAddress.create("aeron:udp", "127.0.0.1", 39790); - - AeronClientChannelConnector.AeronClientConfig config = - AeronClientChannelConnector.AeronClientConfig.create( - receiveAddress, sendAddress, clientId, serverId, clientEventLoop); - - AeronClientChannelConnector connector = - AeronClientChannelConnector.create( - aeronWrapper, clientManagementSocketAddress, clientEventLoop); - - // Create Server - - AeronChannelServer.AeronChannelConsumer consumer = - (AeronChannel aeronChannel) -> { - Assert.assertNotNull(aeronChannel); - - Flux receive = aeronChannel.receive(); - - Flux data = - receive.doOnNext(b -> System.out.println("server received => " + b.getInt(0))); - - aeronChannel.send(data).subscribe(); - }; - - AeronSocketAddress serverManagementSocketAddress = - AeronSocketAddress.create("aeron:udp", "127.0.0.1", 39790); - EventLoop serverEventLoop = new SingleThreadedEventLoop("server"); - AeronChannelServer aeronChannelServer = - AeronChannelServer.create( - consumer, aeronWrapper, serverManagementSocketAddress, serverEventLoop); - - aeronChannelServer.start(); - - Publisher publisher = connector.apply(config); - - int count = 10; - CountDownLatch latch = new CountDownLatch(count); - - Mono.from(publisher) - .flatMap( - aeronChannel -> - Mono.create( - callback -> { - Flux data = - Flux.range(1, count) - .map( - i -> { - byte[] b = new byte[BitUtil.SIZE_OF_INT]; - UnsafeBuffer buffer = new UnsafeBuffer(b); - buffer.putInt(0, i); - return buffer; - }); - - aeronChannel - .receive() - .doOnNext(b -> latch.countDown()) - .doOnNext(callback::success) - .subscribe(); - aeronChannel.send(data).subscribe(); - })) - .subscribe(); - - latch.await(); - } -} diff --git a/rsocket-transport-aeron/src/test/resources/log4j.properties b/rsocket-transport-aeron/src/test/resources/log4j.properties deleted file mode 100644 index 6477d125f..000000000 --- a/rsocket-transport-aeron/src/test/resources/log4j.properties +++ /dev/null @@ -1,33 +0,0 @@ -# -# Copyright 2016 Netflix, Inc. -#

-# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -#

-# http://www.apache.org/licenses/LICENSE-2.0 -#

-# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on -# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the -# specific language governing permissions and limitations under the License. -# - - -# -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -log4j.rootLogger=INFO, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss,SSS} %5p [%t] (%F:%L) - %m%n \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index f32f1e087..16630076a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -21,6 +21,5 @@ include 'rsocket-examples' include 'rsocket-load-balancer' include 'rsocket-micrometer' include 'rsocket-test' -include 'rsocket-transport-aeron' include 'rsocket-transport-local' include 'rsocket-transport-netty'