Add BaseP2PService

This commit is contained in:
Manfred Karrer 2015-03-20 11:56:14 +01:00
parent 79698df651
commit fa900219b2
6 changed files with 60 additions and 27 deletions

View file

@ -32,7 +32,7 @@ import io.bitsquare.locale.LanguageUtil;
import io.bitsquare.p2p.BootstrapState; import io.bitsquare.p2p.BootstrapState;
import io.bitsquare.p2p.ClientNode; import io.bitsquare.p2p.ClientNode;
import io.bitsquare.p2p.MessageService; import io.bitsquare.p2p.MessageService;
import io.bitsquare.p2p.P2PService; import io.bitsquare.p2p.BaseP2PService;
import io.bitsquare.persistence.Persistence; import io.bitsquare.persistence.Persistence;
import io.bitsquare.trade.Trade; import io.bitsquare.trade.Trade;
import io.bitsquare.trade.TradeManager; import io.bitsquare.trade.TradeManager;
@ -159,7 +159,7 @@ class MainViewModel implements ViewModel {
() -> Platform.runLater(() -> setBitcoinNetworkSyncProgress(1.0))); () -> Platform.runLater(() -> setBitcoinNetworkSyncProgress(1.0)));
// Set executor for all P2PServices // Set executor for all P2PServices
P2PService.setUserThread(Platform::runLater); BaseP2PService.setUserThread(Platform::runLater);
Observable<BootstrapState> bootstrapStateAsObservable = clientNode.bootstrap(user.getMessageKeyPair()); Observable<BootstrapState> bootstrapStateAsObservable = clientNode.bootstrap(user.getMessageKeyPair());
bootstrapStateAsObservable.publish(); bootstrapStateAsObservable.publish();

View file

@ -0,0 +1,47 @@
/*
* 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.p2p;
import java.util.concurrent.Executor;
import net.tomp2p.dht.PeerDHT;
public class BaseP2PService implements P2PService {
private static Executor userThread;
public static void setUserThread(Executor userThread) {
BaseP2PService.userThread = userThread;
}
protected Executor executor = userThread;
protected PeerDHT peerDHT;
@Override
public void bootstrapCompleted() {
}
@Override
public void setExecutor(Executor executor) {
this.executor = executor;
}
@Override
public void shutDown() {
}
}

View file

@ -19,26 +19,10 @@ package io.bitsquare.p2p;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import net.tomp2p.dht.PeerDHT; public interface P2PService {
void bootstrapCompleted();
public class P2PService { void setExecutor(Executor executor);
private static Executor userThread; void shutDown();
public static void setUserThread(Executor userThread) {
P2PService.userThread = userThread;
}
protected Executor executor = userThread;
protected PeerDHT peerDHT;
public void bootstrapCompleted() {
}
public void setExecutor(Executor executor) {
this.executor = executor;
}
public void shutDown() {
}
} }

View file

@ -71,6 +71,7 @@ public class TomP2PAddressService extends TomP2PDHTService implements AddressSer
@Override @Override
public void bootstrapCompleted() { public void bootstrapCompleted() {
super.bootstrapCompleted();
setupTimerForIPCheck(); setupTimerForIPCheck();
setupTimerForStoreAddress(); setupTimerForStoreAddress();
storeAddress(); storeAddress();

View file

@ -52,6 +52,7 @@ public class TomP2PMessageService extends TomP2PService implements MessageServic
@Override @Override
public void bootstrapCompleted() { public void bootstrapCompleted() {
super.bootstrapCompleted();
setupReplyHandler(); setupReplyHandler();
} }

View file

@ -18,7 +18,7 @@
package io.bitsquare.p2p.tomp2p; package io.bitsquare.p2p.tomp2p;
import io.bitsquare.p2p.BootstrapState; import io.bitsquare.p2p.BootstrapState;
import io.bitsquare.p2p.P2PService; import io.bitsquare.p2p.BaseP2PService;
import javax.inject.Inject; import javax.inject.Inject;
@ -36,7 +36,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 extends P2PService { public class TomP2PService extends BaseP2PService {
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;