Fixed build

This commit is contained in:
Jaime Freire
2023-11-25 08:18:02 +01:00
parent db9bb4ccdf
commit 789a5f6abc
141 changed files with 3259 additions and 2957 deletions

View File

@ -17,11 +17,11 @@
*/
package org.apache.gossip.transport.udp;
import lombok.extern.slf4j.Slf4j;
import org.apache.gossip.manager.GossipCore;
import org.apache.gossip.manager.GossipManager;
import org.apache.gossip.model.Base;
import org.apache.gossip.transport.AbstractTransportManager;
import org.apache.log4j.Logger;
import java.io.IOException;
import java.net.DatagramPacket;
@ -34,32 +34,33 @@ import java.net.URI;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* This class is constructed by reflection in GossipManager.
* It manages transport (byte read/write) operations over UDP.
* This class is constructed by reflection in GossipManager. It manages transport (byte read/write)
* operations over UDP.
*/
@Slf4j
public class UdpTransportManager extends AbstractTransportManager implements Runnable {
public static final Logger LOGGER = Logger.getLogger(UdpTransportManager.class);
/** The socket used for the passive thread of the gossip service. */
private final DatagramSocket server;
private final int soTimeout;
private final Thread me;
private final AtomicBoolean keepRunning = new AtomicBoolean(true);
/** required for reflection to work! */
public UdpTransportManager(GossipManager gossipManager, GossipCore gossipCore) {
super(gossipManager, gossipCore);
soTimeout = gossipManager.getSettings().getGossipInterval() * 2;
try {
SocketAddress socketAddress = new InetSocketAddress(gossipManager.getMyself().getUri().getHost(),
SocketAddress socketAddress =
new InetSocketAddress(
gossipManager.getMyself().getUri().getHost(),
gossipManager.getMyself().getUri().getPort());
server = new DatagramSocket(socketAddress);
} catch (SocketException ex) {
LOGGER.warn(ex);
log.warn("Warn!", ex);
throw new RuntimeException(ex);
}
me = new Thread(this);
@ -73,21 +74,21 @@ public class UdpTransportManager extends AbstractTransportManager implements Run
try {
Base message = gossipManager.getProtocolManager().read(buf);
gossipCore.receive(message);
//TODO this is suspect
// TODO this is suspect
gossipManager.getMemberStateRefresher().run();
} catch (RuntimeException ex) {//TODO trap json exception
LOGGER.error("Unable to process message", ex);
} catch (RuntimeException ex) { // TODO trap json exception
log.error("Unable to process message", ex);
}
} catch (IOException e) {
// InterruptedException are completely normal here because of the blocking lifecycle.
if (!(e.getCause() instanceof InterruptedException)) {
LOGGER.error(e);
log.error("Error", e);
}
keepRunning.set(false);
}
}
}
@Override
public void shutdown() {
keepRunning.set(false);
@ -98,6 +99,7 @@ public class UdpTransportManager extends AbstractTransportManager implements Run
/**
* blocking read a message.
*
* @return buffer of message contents.
* @throws IOException
*/
@ -111,25 +113,22 @@ public class UdpTransportManager extends AbstractTransportManager implements Run
@Override
public void send(URI endpoint, byte[] buf) throws IOException {
// todo: investigate UDP socket reuse. It would save a little setup/teardown time wrt to the local socket.
try (DatagramSocket socket = new DatagramSocket()){
// todo: investigate UDP socket reuse. It would save a little setup/teardown time wrt to the
// local socket.
try (DatagramSocket socket = new DatagramSocket()) {
socket.setSoTimeout(soTimeout);
InetAddress dest = InetAddress.getByName(endpoint.getHost());
DatagramPacket payload = new DatagramPacket(buf, buf.length, dest, endpoint.getPort());
socket.send(payload);
}
}
private void debug(byte[] jsonBytes) {
if (LOGGER.isDebugEnabled()){
String receivedMessage = new String(jsonBytes);
LOGGER.debug("Received message ( bytes): " + receivedMessage);
}
log.debug("Received message ( bytes): {}", jsonBytes);
}
@Override
public void startEndpoint() {
me.start();
}
}

View File

@ -21,40 +21,39 @@ import org.junit.Ignore;
import org.junit.Test;
public class UdpTransportIntegrationTest {
// It's currently impossible to create a UdpTransportManager without bringing up an entire stack.
// This is because AbstractTransportManager creates a PassiveGossipThread (requires GossipManager,
// GossipCore) and also requires those same things plus a MetricsRegistry to create the
// This is because AbstractTransportManager creates a PassiveGossipThread (requires GossipManager,
// GossipCore) and also requires those same things plus a MetricsRegistry to create the
// ActiveGossiper.
// TODO: test UDPTransportManger semantics (read and write) in isolation.
// I've written this test to indicate the direction I want things to go.
// Uncomment/Fix it once the coupling issues are worked out.
@Test @Ignore
@Test
@Ignore
public void testRoundTrip() {
/*
GossipSettings settings0 = new GossipSettings();
GossipSettings settings1 = new GossipSettings();
UdpTransportManager mgr0 = new UdpTransportManager(settings0);
UdpTransportManager mgr1 = new UdpTransportManager(settings1);
mgr0.startEndpoint();
mgr1.startEndpoint();
mgr0.startActiveGossiper();
mgr1.startActiveGossiper();
// wait a little while for convergence
// perhaps there is a Mockito Whitebox way to foce members
byte[] data = new byte[] {0,1,2,3,4,5};
Future<byte[]> someData = asyncWaitForData(mgr1);
mgr0.send(toURI(settings1), data);
Assert.assertEquals(data, someData.get(1000, TimeUnit.MILLISECONDS));
mgr0.shutdown();
mgr1.shutdown();
*/
}
}