Refactor TomP2P services

This commit is contained in:
Manfred Karrer 2015-03-19 23:58:42 +01:00
parent 3f12247d65
commit 2f2d6b68e0
11 changed files with 20 additions and 43 deletions

View file

@ -40,7 +40,7 @@ import joptsimple.OptionSet;
import static io.bitsquare.app.BitsquareEnvironment.*; import static io.bitsquare.app.BitsquareEnvironment.*;
import static io.bitsquare.network.Node.*; import static io.bitsquare.network.Node.*;
import static io.bitsquare.network.tomp2p.TomP2PNetworkModule.*; import static io.bitsquare.network.tomp2p.TomP2PModule.*;
import static java.util.Arrays.asList; import static java.util.Arrays.asList;
public class BitsquareAppMain extends BitsquareExecutable { public class BitsquareAppMain extends BitsquareExecutable {

View file

@ -18,13 +18,13 @@
package io.bitsquare.app; package io.bitsquare.app;
import io.bitsquare.BitsquareModule; import io.bitsquare.BitsquareModule;
import io.bitsquare.arbitration.ArbitratorMessageModule; import io.bitsquare.arbitration.ArbitratorModule;
import io.bitsquare.arbitration.tomp2p.TomP2PArbitratorMessageModule; import io.bitsquare.arbitration.tomp2p.TomP2PArbitratorModule;
import io.bitsquare.btc.BitcoinModule; import io.bitsquare.btc.BitcoinModule;
import io.bitsquare.crypto.CryptoModule; import io.bitsquare.crypto.CryptoModule;
import io.bitsquare.gui.GuiModule; import io.bitsquare.gui.GuiModule;
import io.bitsquare.network.NetworkModule; import io.bitsquare.network.NetworkModule;
import io.bitsquare.network.tomp2p.TomP2PNetworkModule; import io.bitsquare.network.tomp2p.TomP2PModule;
import io.bitsquare.offer.OfferModule; import io.bitsquare.offer.OfferModule;
import io.bitsquare.offer.tomp2p.TomP2POfferModule; import io.bitsquare.offer.tomp2p.TomP2POfferModule;
import io.bitsquare.persistence.Persistence; import io.bitsquare.persistence.Persistence;
@ -76,12 +76,12 @@ class BitsquareAppModule extends BitsquareModule {
install(guiModule()); install(guiModule());
} }
protected ArbitratorMessageModule arbitratorMessageModule() { protected ArbitratorModule arbitratorMessageModule() {
return new TomP2PArbitratorMessageModule(env); return new TomP2PArbitratorModule(env);
} }
protected NetworkModule networkModule() { protected NetworkModule networkModule() {
return new TomP2PNetworkModule(env); return new TomP2PModule(env);
} }
protected BitcoinModule bitcoinModule() { protected BitcoinModule bitcoinModule() {

View file

@ -21,9 +21,9 @@ import io.bitsquare.BitsquareModule;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
public abstract class ArbitratorMessageModule extends BitsquareModule { public abstract class ArbitratorModule extends BitsquareModule {
protected ArbitratorMessageModule(Environment env) { protected ArbitratorModule(Environment env) {
super(env); super(env);
} }

View file

@ -22,11 +22,8 @@ import io.bitsquare.arbitration.listeners.ArbitratorListener;
import io.bitsquare.network.DHTService; import io.bitsquare.network.DHTService;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.Executor;
public interface ArbitratorService extends DHTService { public interface ArbitratorService extends DHTService {
void setExecutor(Executor executor);
void addArbitrator(Arbitrator arbitrator); void addArbitrator(Arbitrator arbitrator);
void addArbitratorListener(ArbitratorListener listener); void addArbitratorListener(ArbitratorListener listener);

View file

@ -17,16 +17,16 @@
package io.bitsquare.arbitration.tomp2p; package io.bitsquare.arbitration.tomp2p;
import io.bitsquare.arbitration.ArbitratorMessageModule; import io.bitsquare.arbitration.ArbitratorModule;
import io.bitsquare.arbitration.ArbitratorService; import io.bitsquare.arbitration.ArbitratorService;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
public class TomP2PArbitratorMessageModule extends ArbitratorMessageModule { public class TomP2PArbitratorModule extends ArbitratorModule {
public TomP2PArbitratorMessageModule(Environment env) { public TomP2PArbitratorModule(Environment env) {
super(env); super(env);
} }

View file

@ -25,7 +25,7 @@ import net.tomp2p.dht.FutureRemove;
import net.tomp2p.peers.Number160; import net.tomp2p.peers.Number160;
import net.tomp2p.storage.Data; import net.tomp2p.storage.Data;
public interface DHTService extends NetworkService { public interface DHTService extends P2PService {
FuturePut putDomainProtectedData(Number160 locationKey, Data data); FuturePut putDomainProtectedData(Number160 locationKey, Data data);

View file

@ -20,7 +20,7 @@ package io.bitsquare.network;
import io.bitsquare.network.listener.SendMessageListener; import io.bitsquare.network.listener.SendMessageListener;
public interface MessageService extends NetworkService, MessageHandler { public interface MessageService extends P2PService, MessageHandler {
void sendMessage(Peer peer, Message message, SendMessageListener listener); void sendMessage(Peer peer, Message message, SendMessageListener listener);

View file

@ -19,7 +19,7 @@ package io.bitsquare.network;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
public interface NetworkService { public interface P2PService {
void setExecutor(Executor executor); void setExecutor(Executor executor);
void bootstrapCompleted(); void bootstrapCompleted();

View file

@ -32,14 +32,14 @@ import org.springframework.core.env.Environment;
import static io.bitsquare.network.tomp2p.BootstrappedPeerBuilder.*; import static io.bitsquare.network.tomp2p.BootstrappedPeerBuilder.*;
public class TomP2PNetworkModule extends NetworkModule { public class TomP2PModule extends NetworkModule {
public static final String BOOTSTRAP_NODE_NAME_KEY = "bootstrap.node.name"; public static final String BOOTSTRAP_NODE_NAME_KEY = "bootstrap.node.name";
public static final String BOOTSTRAP_NODE_IP_KEY = "bootstrap.node.ip"; public static final String BOOTSTRAP_NODE_IP_KEY = "bootstrap.node.ip";
public static final String BOOTSTRAP_NODE_PORT_KEY = "bootstrap.node.port"; public static final String BOOTSTRAP_NODE_PORT_KEY = "bootstrap.node.port";
public static final String NETWORK_INTERFACE_KEY = BootstrappedPeerBuilder.NETWORK_INTERFACE_KEY; public static final String NETWORK_INTERFACE_KEY = BootstrappedPeerBuilder.NETWORK_INTERFACE_KEY;
public static final String USE_MANUAL_PORT_FORWARDING_KEY = BootstrappedPeerBuilder.USE_MANUAL_PORT_FORWARDING_KEY; public static final String USE_MANUAL_PORT_FORWARDING_KEY = BootstrappedPeerBuilder.USE_MANUAL_PORT_FORWARDING_KEY;
public TomP2PNetworkModule(Environment env) { public TomP2PModule(Environment env) {
super(env); super(env);
} }

View file

@ -18,7 +18,7 @@
package io.bitsquare.network.tomp2p; package io.bitsquare.network.tomp2p;
import io.bitsquare.network.BootstrapState; import io.bitsquare.network.BootstrapState;
import io.bitsquare.network.NetworkService; import io.bitsquare.network.P2PService;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
@ -42,7 +42,7 @@ import rx.Subscriber;
* That way we limit the dependency of the TomP2P library only to that class (and it's sub components). * That way we limit the dependency of the TomP2P library only to that class (and it's sub components).
* <p/> * <p/>
*/ */
public class TomP2PService implements NetworkService { public class TomP2PService implements P2PService {
private static final Logger log = LoggerFactory.getLogger(TomP2PService.class); private static final Logger log = LoggerFactory.getLogger(TomP2PService.class);
private final Subscriber<BootstrapState> subscriber; private final Subscriber<BootstrapState> subscriber;

View file

@ -17,17 +17,11 @@
package io.bitsquare.offer.tomp2p; package io.bitsquare.offer.tomp2p;
import io.bitsquare.network.tomp2p.TomP2PNode;
import io.bitsquare.offer.OfferBookService; import io.bitsquare.offer.OfferBookService;
import io.bitsquare.offer.OfferModule; import io.bitsquare.offer.OfferModule;
import com.google.inject.Provider;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import javax.inject.Inject;
import javafx.application.Platform;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
public class TomP2POfferModule extends OfferModule { public class TomP2POfferModule extends OfferModule {
@ -39,20 +33,6 @@ public class TomP2POfferModule extends OfferModule {
@Override @Override
protected void configure() { protected void configure() {
super.configure(); super.configure();
bind(OfferBookService.class).toProvider(OfferBookServiceProvider.class).in(Singleton.class); bind(OfferBookService.class).to(TomP2POfferBookService.class).in(Singleton.class);
}
}
class OfferBookServiceProvider implements Provider<OfferBookService> {
private final OfferBookService offerBookService;
@Inject
public OfferBookServiceProvider(TomP2PNode tomP2PNode) {
offerBookService = new TomP2POfferBookService(tomP2PNode);
offerBookService.setExecutor(Platform::runLater);
}
public OfferBookService get() {
return offerBookService;
} }
} }