Skip to content

Commit

Permalink
Object Streaming API
Browse files Browse the repository at this point in the history
  • Loading branch information
apangin committed Dec 26, 2018
1 parent b252e30 commit 8b102e9
Show file tree
Hide file tree
Showing 12 changed files with 1,295 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/one/nio/rpc/stream/BaseStream.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2018 Odnoklassniki Ltd, Mail.Ru Group
*
* 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 one.nio.rpc.stream;

import java.net.InetSocketAddress;

public interface BaseStream extends AutoCloseable {
InetSocketAddress getLocalAddress();
InetSocketAddress getRemoteAddress();

long getBytesRead();
long getBytesWritten();

void close();
}
28 changes: 28 additions & 0 deletions src/one/nio/rpc/stream/BidiStream.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2018 Odnoklassniki Ltd, Mail.Ru Group
*
* 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 one.nio.rpc.stream;

import java.io.IOException;

public interface BidiStream<S, R> extends SendStream<S>, ReceiveStream<R> {
void flush() throws IOException;
R sendAndGet(S object) throws IOException, ClassNotFoundException;

static <Q, R> BidiStream<Q, R> create(StreamHandler<BidiStream<R, Q>> handler) {
return new StreamProxy<>(handler);
}
}
27 changes: 27 additions & 0 deletions src/one/nio/rpc/stream/ReceiveStream.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2018 Odnoklassniki Ltd, Mail.Ru Group
*
* 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 one.nio.rpc.stream;

import java.io.IOException;

public interface ReceiveStream<R> extends BaseStream {
R receive() throws IOException, ClassNotFoundException;

static <R> ReceiveStream<R> create(StreamHandler<SendStream<R>> handler) {
return new StreamProxy<>(handler);
}
}
31 changes: 31 additions & 0 deletions src/one/nio/rpc/stream/RpcStream.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2018 Odnoklassniki Ltd, Mail.Ru Group
*
* 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 one.nio.rpc.stream;

import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.nio.ByteBuffer;

public interface RpcStream extends BaseStream, ObjectInput, ObjectOutput {
void read(ByteBuffer buf) throws IOException;
void write(ByteBuffer buf) throws IOException;

static RpcStream create(StreamHandler<RpcStream> handler) {
return new StreamProxy<>(handler);
}
}
Loading

0 comments on commit 8b102e9

Please sign in to comment.