Remove TradeMessageModule

This commit is contained in:
Manfred Karrer 2015-03-19 21:21:38 +01:00
parent ea1afdebee
commit 264f37a73f
14 changed files with 41 additions and 107 deletions

View file

@ -18,7 +18,6 @@
package io.bitsquare.app;
import io.bitsquare.BitsquareModule;
import io.bitsquare.user.AccountSettings;
import io.bitsquare.arbitration.ArbitratorMessageModule;
import io.bitsquare.arbitration.tomp2p.TomP2PArbitratorMessageModule;
import io.bitsquare.btc.BitcoinModule;
@ -29,9 +28,9 @@ import io.bitsquare.network.tomp2p.TomP2PNetworkModule;
import io.bitsquare.offer.OfferModule;
import io.bitsquare.offer.tomp2p.TomP2POfferModule;
import io.bitsquare.persistence.Persistence;
import io.bitsquare.trade.TradeModule;
import io.bitsquare.user.AccountSettings;
import io.bitsquare.user.Preferences;
import io.bitsquare.trade.TradeMessageModule;
import io.bitsquare.trade.tomp2p.TomP2PTradeMessageModule;
import io.bitsquare.user.User;
import com.google.inject.Injector;
@ -93,8 +92,8 @@ class BitsquareAppModule extends BitsquareModule {
return new CryptoModule(env);
}
protected TradeMessageModule tradeMessageModule() {
return new TomP2PTradeMessageModule(env);
protected TradeModule tradeMessageModule() {
return new TradeModule(env);
}
protected OfferModule offerModule() {

View file

@ -34,7 +34,7 @@ import io.bitsquare.network.ClientNode;
import io.bitsquare.persistence.Persistence;
import io.bitsquare.trade.Trade;
import io.bitsquare.trade.TradeManager;
import io.bitsquare.trade.TradeMessageService;
import io.bitsquare.network.TradeMessageService;
import io.bitsquare.user.User;
import io.bitsquare.util.DSAKeyUtil;
import io.bitsquare.common.viewfx.model.ViewModel;

View file

@ -1,24 +0,0 @@
/*
* This file is part of Bitsquare.
*
* Bitsquare is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bitsquare is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/
package io.bitsquare.network;
public interface MessageHandler {
public void handle(Object message);
}

View file

@ -15,11 +15,8 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/
package io.bitsquare.trade;
package io.bitsquare.network;
import io.bitsquare.network.Message;
import io.bitsquare.network.MessageBroker;
import io.bitsquare.network.Peer;
import io.bitsquare.trade.handlers.MessageHandler;
import io.bitsquare.trade.listeners.GetPeerAddressListener;
import io.bitsquare.trade.listeners.SendMessageListener;

View file

@ -15,13 +15,11 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/
package io.bitsquare.trade.tomp2p;
package io.bitsquare.network.tomp2p;
import io.bitsquare.network.Message;
import io.bitsquare.network.Peer;
import io.bitsquare.network.tomp2p.TomP2PNode;
import io.bitsquare.network.tomp2p.TomP2PPeer;
import io.bitsquare.trade.TradeMessageService;
import io.bitsquare.network.TradeMessageService;
import io.bitsquare.trade.handlers.MessageHandler;
import io.bitsquare.trade.listeners.GetPeerAddressListener;
import io.bitsquare.trade.listeners.SendMessageListener;
@ -50,8 +48,8 @@ import org.slf4j.LoggerFactory;
* That way we limit the dependency of the TomP2P library only to that class (and it's sub components).
* <p/>
*/
public class TomP2PTradeMessageService implements TradeMessageService {
private static final Logger log = LoggerFactory.getLogger(TomP2PTradeMessageService.class);
public class TomP2PMessageService implements TradeMessageService {
private static final Logger log = LoggerFactory.getLogger(TomP2PMessageService.class);
private final TomP2PNode tomP2PNode;
private final CopyOnWriteArrayList<MessageHandler> messageHandlers = new CopyOnWriteArrayList<>();
@ -62,7 +60,7 @@ public class TomP2PTradeMessageService implements TradeMessageService {
// Constructor
///////////////////////////////////////////////////////////////////////////////////////////
public TomP2PTradeMessageService(TomP2PNode tomP2PNode) {
public TomP2PMessageService(TomP2PNode tomP2PNode) {
this.tomP2PNode = tomP2PNode;
}

View file

@ -21,11 +21,17 @@ import io.bitsquare.network.BootstrapNodes;
import io.bitsquare.network.ClientNode;
import io.bitsquare.network.NetworkModule;
import io.bitsquare.network.Node;
import io.bitsquare.network.TradeMessageService;
import com.google.inject.Injector;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import com.google.inject.name.Names;
import javax.inject.Inject;
import javafx.application.Platform;
import org.springframework.core.env.Environment;
import static io.bitsquare.network.tomp2p.BootstrappedPeerBuilder.*;
@ -45,6 +51,7 @@ public class TomP2PNetworkModule extends NetworkModule {
protected void doConfigure() {
bind(ClientNode.class).to(TomP2PNode.class).in(Singleton.class);
bind(TomP2PNode.class).in(Singleton.class);
bind(TradeMessageService.class).toProvider(TomP2PTradeMessageServiceProvider.class).in(Singleton.class);
bind(int.class).annotatedWith(Names.named(Node.PORT_KEY)).toInstance(env.getProperty(Node.PORT_KEY, int.class, Node.DEFAULT_PORT));
bind(boolean.class).annotatedWith(Names.named(USE_MANUAL_PORT_FORWARDING_KEY)).toInstance(
@ -69,3 +76,16 @@ public class TomP2PNetworkModule extends NetworkModule {
injector.getInstance(BootstrappedPeerBuilder.class).shutDown();
}
}
class TomP2PTradeMessageServiceProvider implements Provider<TradeMessageService> {
private final TradeMessageService tradeMessageService;
@Inject
public TomP2PTradeMessageServiceProvider(TomP2PNode tomP2PNode) {
tradeMessageService = new TomP2PMessageService(tomP2PNode);
tradeMessageService.setExecutor(Platform::runLater);
}
public TradeMessageService get() {
return tradeMessageService;
}
}

View file

@ -25,6 +25,7 @@ import io.bitsquare.crypto.SignatureService;
import io.bitsquare.fiat.FiatAccount;
import io.bitsquare.network.Message;
import io.bitsquare.network.Peer;
import io.bitsquare.network.TradeMessageService;
import io.bitsquare.offer.Direction;
import io.bitsquare.offer.Offer;
import io.bitsquare.offer.OfferBookService;

View file

@ -23,9 +23,9 @@ import com.google.inject.Singleton;
import org.springframework.core.env.Environment;
public abstract class TradeMessageModule extends BitsquareModule {
public class TradeModule extends BitsquareModule {
protected TradeMessageModule(Environment env) {
public TradeModule(Environment env) {
super(env);
}

View file

@ -20,7 +20,7 @@ package io.bitsquare.trade.protocol.availability;
import io.bitsquare.common.taskrunner.SharedTaskModel;
import io.bitsquare.network.Peer;
import io.bitsquare.offer.Offer;
import io.bitsquare.trade.TradeMessageService;
import io.bitsquare.network.TradeMessageService;
import io.bitsquare.trade.protocol.trade.messages.OfferMessage;
import org.slf4j.Logger;

View file

@ -24,7 +24,7 @@ import io.bitsquare.common.taskrunner.SharedTaskModel;
import io.bitsquare.crypto.SignatureService;
import io.bitsquare.offer.Offer;
import io.bitsquare.persistence.Persistence;
import io.bitsquare.trade.TradeMessageService;
import io.bitsquare.network.TradeMessageService;
import io.bitsquare.trade.protocol.trade.messages.TradeMessage;
import java.io.Serializable;

View file

@ -22,7 +22,7 @@ import io.bitsquare.btc.WalletService;
import io.bitsquare.crypto.SignatureService;
import io.bitsquare.persistence.Persistence;
import io.bitsquare.trade.Trade;
import io.bitsquare.trade.TradeMessageService;
import io.bitsquare.network.TradeMessageService;
import io.bitsquare.trade.protocol.trade.SharedTradeModel;
import io.bitsquare.user.User;

View file

@ -23,7 +23,7 @@ import io.bitsquare.crypto.SignatureService;
import io.bitsquare.network.Peer;
import io.bitsquare.persistence.Persistence;
import io.bitsquare.trade.Trade;
import io.bitsquare.trade.TradeMessageService;
import io.bitsquare.network.TradeMessageService;
import io.bitsquare.trade.protocol.trade.SharedTradeModel;
import io.bitsquare.user.User;

View file

@ -1,57 +0,0 @@
/*
* This file is part of Bitsquare.
*
* Bitsquare is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bitsquare is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/
package io.bitsquare.trade.tomp2p;
import io.bitsquare.network.tomp2p.TomP2PNode;
import io.bitsquare.trade.TradeMessageModule;
import io.bitsquare.trade.TradeMessageService;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import javax.inject.Inject;
import javafx.application.Platform;
import org.springframework.core.env.Environment;
public class TomP2PTradeMessageModule extends TradeMessageModule {
public TomP2PTradeMessageModule(Environment env) {
super(env);
}
@Override
protected void doConfigure() {
bind(TradeMessageService.class).toProvider(TomP2PTradeMessageServiceProvider.class).in(Singleton.class);
}
}
class TomP2PTradeMessageServiceProvider implements Provider<TradeMessageService> {
private final TradeMessageService tradeMessageService;
@Inject
public TomP2PTradeMessageServiceProvider(TomP2PNode tomP2PNode) {
tradeMessageService = new TomP2PTradeMessageService(tomP2PNode);
tradeMessageService.setExecutor(Platform::runLater);
}
public TradeMessageService get() {
return tradeMessageService;
}
}

View file

@ -34,8 +34,8 @@ import io.bitsquare.offer.Offer;
import io.bitsquare.offer.OfferBookService;
import io.bitsquare.offer.tomp2p.TomP2POfferBookService;
import io.bitsquare.persistence.Persistence;
import io.bitsquare.trade.TradeMessageService;
import io.bitsquare.trade.tomp2p.TomP2PTradeMessageService;
import io.bitsquare.network.TradeMessageService;
import io.bitsquare.network.tomp2p.TomP2PMessageService;
import io.bitsquare.user.User;
import io.bitsquare.util.DSAKeyUtil;
@ -96,7 +96,7 @@ public class PlaceOfferProtocolTest {
user.applyPersistedUser(null);
bootstrappedPeerBuilder = new BootstrappedPeerBuilder(Node.DEFAULT_PORT, false, bootstrapNode, "<unspecified>");
tomP2PNode = new TomP2PNode(bootstrappedPeerBuilder);
tradeMessageService = new TomP2PTradeMessageService(tomP2PNode);
tradeMessageService = new TomP2PMessageService(tomP2PNode);
Observable<BootstrapState> messageObservable = tomP2PNode.bootstrap(user.getMessageKeyPair(), tradeMessageService);
messageObservable.publish();