Skip to content

Commit

Permalink
rename RelpRead to Ingress and RelpWrite to Egress (#203)
Browse files Browse the repository at this point in the history
* rename RelpRead to Ingress and RelpWrite to Egress

* rename method relpWrite() to egress() in EstablishedContext
  • Loading branch information
kortemik authored Jun 24, 2024
1 parent 27fb7df commit 16c844d
Show file tree
Hide file tree
Showing 16 changed files with 40 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
/**
* Egress {@link com.teragrep.rlp_03.frame.RelpFrame} are handled by this
*/
public interface RelpWrite extends Consumer<Writeable>, Runnable {
public interface Egress extends Consumer<Writeable>, Runnable {

/**
* Sends asynchronously the writeable provided. Implementation is required to be thread-safe.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@
import static java.nio.channels.SelectionKey.OP_READ;
import static java.nio.channels.SelectionKey.OP_WRITE;

final class RelpWriteImpl implements RelpWrite {
final class EgressImpl implements Egress {

private static final Logger LOGGER = LoggerFactory.getLogger(RelpWriteImpl.class);
private static final Logger LOGGER = LoggerFactory.getLogger(EgressImpl.class);

private final EstablishedContext establishedContext;

Expand All @@ -83,7 +83,7 @@ final class RelpWriteImpl implements RelpWrite {

private final List<Writeable> toWriteList;

RelpWriteImpl(EstablishedContext establishedContext) {
EgressImpl(EstablishedContext establishedContext) {
this.establishedContext = establishedContext;
this.queue = new ConcurrentLinkedQueue<>();
this.writeInProgressList = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@

/**
* Established type of {@link Context}. It produces ingress data into the provided
* {@link com.teragrep.rlp_03.frame.delegate.FrameDelegate} via {@link RelpRead}. Egress data can be written via
* {@link RelpWrite#accept(Writeable)}.
* {@link com.teragrep.rlp_03.frame.delegate.FrameDelegate} via {@link Ingress}. Egress data can be written via
* {@link Egress#accept(Writeable)}.
*/
public interface EstablishedContext extends Context {

Expand All @@ -68,5 +68,5 @@ public interface EstablishedContext extends Context {
/**
* @return RelpWrite of the connection for sending egress data.
*/
RelpWrite relpWrite();
Egress egress();
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ final class EstablishedContextImpl implements EstablishedContext {
private final Clock clock;

private final BufferLeasePool bufferLeasePool;
private final RelpRead relpRead;
private final RelpWrite relpWrite;
private final Ingress ingress;
private final Egress egress;

EstablishedContextImpl(
ExecutorService executorService,
Expand All @@ -88,8 +88,8 @@ final class EstablishedContextImpl implements EstablishedContext {
this.clock = clockFactory.create(this);

this.bufferLeasePool = new BufferLeasePool();
this.relpRead = new RelpReadImpl(this, this.bufferLeasePool, clock);
this.relpWrite = new RelpWriteImpl(this);
this.ingress = new IngressImpl(this, this.bufferLeasePool, clock);
this.egress = new EgressImpl(this);

}

Expand Down Expand Up @@ -154,7 +154,7 @@ public void handleEvent(SelectionKey selectionKey) {
}
LOGGER.debug("handleEvent submitting new runnable for read");
try {
executorService.submit(relpRead);
executorService.submit(ingress);
}
catch (RejectedExecutionException ree) {
LOGGER.error("executorService.submit threw <{}> for read", ree.getMessage());
Expand All @@ -180,7 +180,7 @@ public void handleEvent(SelectionKey selectionKey) {
}
LOGGER.debug("handleEvent submitting new runnable for write");
try {
executorService.submit(relpWrite);
executorService.submit(egress);
LOGGER.debug("submitted write!");
}
catch (RejectedExecutionException ree) {
Expand All @@ -207,12 +207,12 @@ public void handleEvent(SelectionKey selectionKey) {
return;
}
// socket write may be pending a tls read
if (relpWrite.needRead().compareAndSet(true, false)) {
executorService.submit(relpWrite);
if (egress.needRead().compareAndSet(true, false)) {
executorService.submit(egress);
}

// read anyway
executorService.submit(relpRead);
executorService.submit(ingress);
}

if (selectionKey.isWritable()) {
Expand All @@ -229,13 +229,13 @@ public void handleEvent(SelectionKey selectionKey) {
close();
return;
}
if (relpRead.needWrite().compareAndSet(true, false)) {
if (ingress.needWrite().compareAndSet(true, false)) {
// socket read may be pending a tls write
executorService.submit(relpRead);
executorService.submit(ingress);
}

// write anyway
executorService.submit(relpWrite);
executorService.submit(egress);
}
}
}
Expand All @@ -251,7 +251,7 @@ public Socket socket() {
}

@Override
public RelpWrite relpWrite() {
return relpWrite;
public Egress egress() {
return egress;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public Socket socket() {
}

@Override
public RelpWrite relpWrite() {
public Egress egress() {
throw new IllegalArgumentException("EstablishedContextStub does not implement this");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
/**
* Ingress {@link com.teragrep.rlp_03.frame.RelpFrame} are handled by this asynchronously.
*/
public interface RelpRead extends Runnable {
public interface Ingress extends Runnable {

@Override
void run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@
import static java.nio.channels.SelectionKey.OP_READ;
import static java.nio.channels.SelectionKey.OP_WRITE;

final class RelpReadImpl implements RelpRead {
final class IngressImpl implements Ingress {

private static final Logger LOGGER = LoggerFactory.getLogger(RelpReadImpl.class);
private static final Logger LOGGER = LoggerFactory.getLogger(IngressImpl.class);
private final EstablishedContextImpl establishedContext;
private final BufferLeasePool bufferLeasePool;

Expand All @@ -77,7 +77,7 @@ final class RelpReadImpl implements RelpRead {

private final Clock clock;

RelpReadImpl(EstablishedContextImpl establishedContext, BufferLeasePool bufferLeasePool, Clock clock) {
IngressImpl(EstablishedContextImpl establishedContext, BufferLeasePool bufferLeasePool, Clock clock) {
this.establishedContext = establishedContext;
this.bufferLeasePool = bufferLeasePool;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/teragrep/rlp_03/client/ClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public CompletableFuture<RelpFrame> transmit(RelpFrame relpFrame) {
);
CompletableFuture<RelpFrame> future = transactionService.create(relpFrameToXmit);

establishedContext.relpWrite().accept(relpFrameToXmit.toWriteable());
establishedContext.egress().accept(relpFrameToXmit.toWriteable());
return future;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void accept(FrameContext frameContext) {
Writeables writeables = new Writeables(framesWriteables);
WriteableClosure writeableClosure = new WriteableClosure(writeables, frameContext.establishedContext());

frameContext.establishedContext().relpWrite().accept(writeableClosure);
frameContext.establishedContext().egress().accept(writeableClosure);
}
finally {
frameContext.relpFrame().close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void accept(FrameContext frameContext) {
responseFrameTemplate.endOfTransfer()
);

frameContext.establishedContext().relpWrite().accept(frame.toWriteable());
frameContext.establishedContext().egress().accept(frame.toWriteable());
}
finally {
frameContext.relpFrame().close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void accept(FrameContext frameContext) {
serverCloseFrame.toWriteable(),
frameContext.establishedContext()
);
frameContext.establishedContext().relpWrite().accept(closingServerClose);
frameContext.establishedContext().egress().accept(closingServerClose);
}
finally {
frameContext.relpFrame().close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void accept(FrameContext frameContext) {
);
}

frameContext.establishedContext().relpWrite().accept(relpFrame.toWriteable());
frameContext.establishedContext().egress().accept(relpFrame.toWriteable());
}
finally {
frameContext.relpFrame().close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

public class RelpWriteFake implements RelpWrite {
public class EgressFake implements Egress {

private final List<Writeable> writtenFrames;

private final AtomicBoolean needRead;

RelpWriteFake() {
EgressFake() {
this.writtenFrames = new LinkedList<>();
this.needRead = new AtomicBoolean();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ public class EstablishedContextFake implements EstablishedContext {
private final InterestOps interestOps;
private final Socket socket;

private final RelpWrite relpWrite;
private final Egress egress;

EstablishedContextFake(InterestOps interestOps, Socket socket, RelpWrite relpWrite) {
EstablishedContextFake(InterestOps interestOps, Socket socket, Egress egress) {
this.interestOps = interestOps;
this.socket = socket;
this.relpWrite = relpWrite;
this.egress = egress;
}

@Override
Expand Down Expand Up @@ -94,7 +94,7 @@ public Socket socket() {
}

@Override
public RelpWrite relpWrite() {
return relpWrite;
public Egress egress() {
return egress;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void init() {

@Override
public boolean accept(FrameContext frameContext) {
// received but will not reply via frameContext.establishedContext().relpWrite();
// received but will not reply via frameContext.establishedContext().egress();
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public void run() {
RelpFrame responseFrame = relpFrameFactory.create(relpFrame.txn().toBytes(), "rsp", "200 OK");

// WARNING: failing to respond causes transaction aware clients to wait
frameContext.establishedContext().relpWrite().accept(responseFrame.toWriteable());
frameContext.establishedContext().egress().accept(responseFrame.toWriteable());
}
}
catch (Exception interruptedException) {
Expand Down

0 comments on commit 16c844d

Please sign in to comment.