bt.peerexchange.PeerExchangeModule Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bt-core Show documentation
Show all versions of bt-core Show documentation
BitTorrent Client Library (Core)
package bt.peerexchange;
import bt.module.ProtocolModule;
import bt.module.ServiceModule;
import com.google.inject.Binder;
import com.google.inject.Module;
import com.google.inject.Singleton;
public class PeerExchangeModule implements Module {
private PeerExchangeConfig config;
public PeerExchangeModule() {
this.config = new PeerExchangeConfig();
}
public PeerExchangeModule(PeerExchangeConfig config) {
this.config = config;
}
@Override
public void configure(Binder binder) {
binder.bind(PeerExchangeConfig.class).toInstance(config);
// explicit singleton binding is required to prevent multibinders from creating 2 instances
// see https://github.com/google/guice/issues/791
binder.bind(PeerExchangePeerSourceFactory.class).in(Singleton.class);
ServiceModule.contributePeerSourceFactory(binder).addBinding()
.to(PeerExchangePeerSourceFactory.class);
ServiceModule.contributeMessagingAgent(binder).addBinding()
.to(PeerExchangePeerSourceFactory.class);
ProtocolModule.contributeExtendedMessageHandler(binder)
.addBinding("ut_pex").to(PeerExchangeMessageHandler.class);
}
}