Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Commit

Permalink
Blocking actions should log all errors, rename runOnce to action ever…
Browse files Browse the repository at this point in the history
…ywhere.
  • Loading branch information
peter-lawrey committed Jun 26, 2015
1 parent 83b0367 commit a97cf87
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<dependency>
<groupId>net.openhft</groupId>
<artifactId>chronicle-bom</artifactId>
<version>1.4.3</version>
<version>1.4.4-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import net.openhft.chronicle.threads.HandlerPriority;
import net.openhft.chronicle.threads.api.EventHandler;
import net.openhft.chronicle.threads.api.EventLoop;
import net.openhft.chronicle.threads.api.InvalidEventHandlerException;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -37,14 +38,13 @@
* Created by peter.lawrey on 22/01/15.
*/
public class AcceptorEventHandler implements EventHandler,Closeable {
private static final Logger LOG = LoggerFactory.getLogger(AcceptorEventHandler.class);
@NotNull
private final Supplier<TcpHandler> tcpHandlerSupplier;
@NotNull
private final Supplier<SessionDetailsProvider> sessionDetailsSupplier;
private EventLoop eventLoop;
private final ServerSocketChannel ssc;

private static final Logger LOG = LoggerFactory.getLogger(AcceptorEventHandler.class);
private EventLoop eventLoop;

public AcceptorEventHandler(int port,
@NotNull final Supplier<TcpHandler> tcpHandlerSupplier,
Expand All @@ -67,7 +67,9 @@ public void eventLoop(EventLoop eventLoop) {
}

@Override
public boolean runOnce() {
public boolean action() throws InvalidEventHandlerException {
if (!ssc.isOpen()) throw new InvalidEventHandlerException();

try {
SocketChannel sc = ssc.accept();

Expand Down Expand Up @@ -109,11 +111,6 @@ public HandlerPriority priority() {
return HandlerPriority.BLOCKING;
}

@Override
public boolean isDead() {
return !ssc.isOpen();
}

@Override
public void close() throws IOException {
closeSocket();
Expand Down
18 changes: 7 additions & 11 deletions src/main/java/net/openhft/chronicle/network/TcpEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.openhft.chronicle.threads.HandlerPriority;
import net.openhft.chronicle.threads.api.EventHandler;
import net.openhft.chronicle.threads.api.EventLoop;
import net.openhft.chronicle.threads.api.InvalidEventHandlerException;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;
Expand Down Expand Up @@ -75,7 +76,9 @@ public void eventLoop(@NotNull EventLoop eventLoop) {
}

@Override
public boolean runOnce() {
public boolean action() throws InvalidEventHandlerException {
if (!sc.isOpen()) throw new InvalidEventHandlerException();

try {
int read = inBB.remaining() > 0 ? sc.read(inBB) : 1;
if (read < 0) {
Expand Down Expand Up @@ -113,10 +116,6 @@ void invokeHandler() throws IOException {
}
}

@Override
public boolean isDead() {
return !sc.isOpen();
}

void handleIOE(@NotNull IOException e) {
e.printStackTrace();
Expand Down Expand Up @@ -146,7 +145,9 @@ boolean tryWrite() throws IOException {

class WriteEventHandler implements EventHandler {
@Override
public boolean runOnce() {
public boolean action() throws InvalidEventHandlerException {
if (!sc.isOpen()) throw new InvalidEventHandlerException();

try {
// get more data to write if the buffer was empty
// or we can write some of what is there
Expand All @@ -162,10 +163,5 @@ public boolean runOnce() {
}
return false;
}

@Override
public boolean isDead() {
return !sc.isOpen();
}
}
}

0 comments on commit a97cf87

Please sign in to comment.