/** * Creates a builder instance. * * @param clusterSettings existing ClusterSettings to default the builder settings on. * @return a builder * @since 3.5 */ public static Builder builder(final ClusterSettings clusterSettings) { return builder().applySettings(clusterSettings); }
public SingleServerCluster(final ClusterId clusterId, final ClusterSettings settings, final ClusterableServerFactory serverFactory) { super(clusterId, settings, serverFactory); isTrue("one server in a direct cluster", settings.getHosts().size() == 1); isTrue("connection mode is single", settings.getMode() == ClusterConnectionMode.SINGLE); if (LOGGER.isInfoEnabled()) { LOGGER.info(format("Cluster created with settings %s", settings.getShortDescription())); } // synchronized in the constructor because the change listener is re-entrant to this instance. // In other words, we are leaking a reference to "this" from the constructor. synchronized (this) { this.server = createServer(settings.getHosts().get(0), new DefaultServerStateListener()); publishDescription(server.getDescription()); } }
/** * Build the settings from the builder. * * @return the cluster settings */ public ClusterSettings build() { return new ClusterSettings(this); } }
AbstractMultiServerCluster(final ClusterId clusterId, final ClusterSettings settings, final ClusterableServerFactory serverFactory) { super(clusterId, settings, serverFactory); isTrue("connection mode is multiple", settings.getMode() == ClusterConnectionMode.MULTIPLE); clusterType = settings.getRequiredClusterType(); replicaSetName = settings.getRequiredReplicaSetName(); if (LOGGER.isInfoEnabled()) { LOGGER.info(format("Cluster created with settings %s", settings.getShortDescription())); } }
public MultiServerCluster(final ClusterId clusterId, final ClusterSettings settings, final ClusterableServerFactory serverFactory) { super(clusterId, settings, serverFactory); isTrue("srvHost is null", settings.getSrvHost() == null); initialize(settings.getHosts()); } }
/** * Gets a list of all server addresses used when this Mongo was created * * @return list of server addresses * @throws MongoException if there's a failure */ @Deprecated public List<ServerAddress> getAllAddress() { return delegate.getCluster().getSettings().getHosts(); }
final List<MongoCompressor> compressorList) { ClusterId clusterId = new ClusterId(clusterSettings.getDescription()); if (clusterSettings.getMode() == ClusterConnectionMode.SINGLE) { return new SingleServerCluster(clusterId, clusterSettings, serverFactory); } else if (clusterSettings.getMode() == ClusterConnectionMode.MULTIPLE) { if (clusterSettings.getSrvHost() == null) { return new MultiServerCluster(clusterId, clusterSettings, serverFactory); } else { throw new UnsupportedOperationException("Unsupported cluster mode: " + clusterSettings.getMode());
private ClusterDescription getInitialDescription() { return new ClusterDescription(getSettings().getMode(), getSettings().getRequiredClusterType(), Collections.<ServerDescription>emptyList(), getSettings(), getServerFactory().getSettings()); } }
private MongoWaitQueueFullException createWaitQueueFullException() { return new MongoWaitQueueFullException(format("Too many operations are already waiting for a server. " + "Max number of operations (maxWaitQueueSize) of %d has " + "been exceeded.", settings.getMaxWaitQueueSize())); }
private ClusterDescription createInitialDescription() { return new ClusterDescription(getSettings().getMode(), ClusterType.UNKNOWN, Collections.<ServerDescription>emptyList(), getSettings(), getServerFactory().getSettings()); }
public static ClusterListener getClusterListener(final ClusterSettings clusterSettings) { switch (clusterSettings.getClusterListeners().size()) { case 0: return NO_OP_CLUSTER_LISTENER; case 1: return clusterSettings.getClusterListeners().get(0); default: return new ClusterListenerMulticaster(clusterSettings.getClusterListeners()); } }
AbstractMultiServerCluster(final ClusterId clusterId, final ClusterSettings settings, final ClusterableServerFactory serverFactory) { super(clusterId, settings, serverFactory); isTrue("connection mode is multiple", settings.getMode() == ClusterConnectionMode.MULTIPLE); clusterType = settings.getRequiredClusterType(); replicaSetName = settings.getRequiredReplicaSetName(); if (LOGGER.isInfoEnabled()) { LOGGER.info(format("Cluster created with settings %s", settings.getShortDescription())); } }
private boolean handleStandAloneChanged(final ServerDescription newDescription) { if (getSettings().getHosts().size() > 1) { LOGGER.error(format("Expecting a single %s, but found more than one. Removing %s from client view of cluster.", STANDALONE, newDescription.getAddress())); clusterType = UNKNOWN; removeServer(newDescription.getAddress()); } return true; }
public MultiServerCluster(final ClusterId clusterId, final ClusterSettings settings, final ClusterableServerFactory serverFactory) { super(clusterId, settings, serverFactory); isTrue("srvHost is null", settings.getSrvHost() == null); initialize(settings.getHosts()); } }
final List<MongoCompressor> compressorList) { ClusterId clusterId = new ClusterId(clusterSettings.getDescription()); if (clusterSettings.getMode() == ClusterConnectionMode.SINGLE) { return new SingleServerCluster(clusterId, clusterSettings, serverFactory); } else if (clusterSettings.getMode() == ClusterConnectionMode.MULTIPLE) { if (clusterSettings.getSrvHost() == null) { return new MultiServerCluster(clusterId, clusterSettings, serverFactory); } else { throw new UnsupportedOperationException("Unsupported cluster mode: " + clusterSettings.getMode());
private ClusterDescription getInitialDescription() { return new ClusterDescription(getSettings().getMode(), getSettings().getRequiredClusterType(), Collections.<ServerDescription>emptyList(), getSettings(), getServerFactory().getSettings()); } }
private synchronized void notifyWaitQueueHandler(final ServerSelectionRequest request) { if (isClosed) { return; } if (waitQueueSize.incrementAndGet() > settings.getMaxWaitQueueSize()) { waitQueueSize.decrementAndGet(); request.onResult(null, createWaitQueueFullException()); } else { waitQueue.add(request); if (waitQueueHandler == null) { waitQueueHandler = new Thread(new WaitQueueHandler(), "cluster-" + clusterId.getValue()); waitQueueHandler.setDaemon(true); waitQueueHandler.start(); } } }
@Override public ClusterableServer create(final ServerAddress serverAddress, final ServerListener serverListener, final ClusterClock clusterClock) { ConnectionPool connectionPool = new DefaultConnectionPool(new ServerId(clusterId, serverAddress), new InternalStreamConnectionFactory(streamFactory, credentialList, applicationName, mongoDriverInformation, compressorList, commandListener), connectionPoolSettings); // no credentials, compressor list, or command listener for the server monitor factory ServerMonitorFactory serverMonitorFactory = new DefaultServerMonitorFactory(new ServerId(clusterId, serverAddress), serverSettings, clusterClock, new InternalStreamConnectionFactory(heartbeatStreamFactory, Collections.<MongoCredentialWithCache>emptyList(), applicationName, mongoDriverInformation, Collections.<MongoCompressor>emptyList(), null), connectionPool); return new DefaultServer(new ServerId(clusterId, serverAddress), clusterSettings.getMode(), connectionPool, new DefaultConnectionFactory(), serverMonitorFactory, serverListener, commandListener, clusterClock); }
public static ClusterListener getClusterListener(final ClusterSettings clusterSettings) { switch (clusterSettings.getClusterListeners().size()) { case 0: return NO_OP_CLUSTER_LISTENER; case 1: return clusterSettings.getClusterListeners().get(0); default: return new ClusterListenerMulticaster(clusterSettings.getClusterListeners()); } }
private ClusterSettings getClusterSettings(final ClusterSettings settings, final ClusterListener clusterListener) { return ClusterSettings.builder(settings).addClusterListener(clusterListener).build(); }