@Test(expectedExceptions = IllegalArgumentException.class) public void testParseWithNullShouldThrowException() { createFor(null, null, null, _mcc); }
@Nonnull public static MemcachedNodesManager createFor(final String memcachedNodes, final String failoverNodes, final StorageKeyFormat storageKeyFormat, final StorageClientCallback storageClientCallback) { if ( memcachedNodes == null || memcachedNodes.trim().isEmpty() ) { throw new IllegalArgumentException("null or empty memcachedNodes not allowed."); } if (memcachedNodes.startsWith("redis: return new MemcachedNodesManager(memcachedNodes, new NodeIdList(), new ArrayList<String>(), new LinkedHashMap<InetSocketAddress, String>(), storageKeyFormat, storageClientCallback); } if ( !NODES_PATTERN.matcher( memcachedNodes ).matches() && !SINGLE_NODE_PATTERN.matcher(memcachedNodes).matches() && !COUCHBASE_BUCKET_NODES_PATTERN.matcher(memcachedNodes).matches()) { throw new IllegalArgumentException( "Configured memcachedNodes attribute has wrong format, must match " + NODES_REGEX ); } final Matcher singleNodeMatcher = SINGLE_NODE_PATTERN.matcher(memcachedNodes); final LinkedHashMap<InetSocketAddress, String> address2Ids = new LinkedHashMap<InetSocketAddress, String>(1); if (singleNodeMatcher.matches()) { address2Ids.put(getSingleShortNodeDefinition(singleNodeMatcher), null); } else if (COUCHBASE_BUCKET_NODES_PATTERN.matcher(memcachedNodes).matches()) { final Matcher matcher = COUCHBASE_BUCKET_NODE_PATTERN.matcher(memcachedNodes); while (matcher.find()) { final String hostname = matcher.group( 1 ); final int port = Integer.parseInt( matcher.group( 2 ) ); address2Ids.put(new InetSocketAddress( hostname, port ), null); } if (address2Ids.isEmpty()) { throw new IllegalArgumentException("All nodes are also configured as failover nodes," + " this is a configuration failure. In this case, you probably want to leave out the failoverNodes."); } } else { final Matcher matcher = NODE_PATTERN.matcher( memcachedNodes); while (matcher.find()) { final Pair<String, InetSocketAddress> nodeInfo = getRegularNodeDefinition(matcher); address2Ids.put(nodeInfo.getSecond(), nodeInfo.getFirst()); } if (address2Ids.isEmpty()) { throw new IllegalArgumentException("All nodes are also configured as failover nodes," + " this is a configuration failure. In this case, you probably want to leave out the failoverNodes."); } } final List<String> failoverNodeIds = initFailoverNodes(failoverNodes, address2Ids.values()); if(address2Ids.size() == 1 && failoverNodeIds.size() >= 1) { throw new IllegalArgumentException("For a single memcached node there should/must no failoverNodes be specified."); } final NodeIdList primaryNodeIds = new NodeIdList(); for(final Map.Entry<InetSocketAddress, String> address2Id : address2Ids.entrySet()) { final String nodeId = address2Id.getValue(); if (nodeId != null && !failoverNodeIds.contains(nodeId) ) { primaryNodeIds.add(nodeId); } } return new MemcachedNodesManager(memcachedNodes, primaryNodeIds, failoverNodeIds, address2Ids, storageKeyFormat, storageClientCallback); }
MemcachedNodesManager { @Nonnull public static MemcachedNodesManager createFor(final String memcachedNodes, final String failoverNodes, final StorageKeyFormat storageKeyFormat, final StorageClientCallback storageClientCallback) { if ( memcachedNodes == null || memcachedNodes.trim().isEmpty() ) { throw new IllegalArgumentException("null or empty memcachedNodes not allowed."); } if (memcachedNodes.startsWith("redis: return new MemcachedNodesManager(memcachedNodes, new NodeIdList(), new ArrayList<String>(), new LinkedHashMap<InetSocketAddress, String>(), storageKeyFormat, storageClientCallback); } if ( !NODES_PATTERN.matcher( memcachedNodes ).matches() && !SINGLE_NODE_PATTERN.matcher(memcachedNodes).matches() && !COUCHBASE_BUCKET_NODES_PATTERN.matcher(memcachedNodes).matches()) { throw new IllegalArgumentException( "Configured memcachedNodes attribute has wrong format, must match " + NODES_REGEX ); } final Matcher singleNodeMatcher = SINGLE_NODE_PATTERN.matcher(memcachedNodes); final LinkedHashMap<InetSocketAddress, String> address2Ids = new LinkedHashMap<InetSocketAddress, String>(1); if (singleNodeMatcher.matches()) { address2Ids.put(getSingleShortNodeDefinition(singleNodeMatcher), null); } else if (COUCHBASE_BUCKET_NODES_PATTERN.matcher(memcachedNodes).matches()) { final Matcher matcher = COUCHBASE_BUCKET_NODE_PATTERN.matcher(memcachedNodes); while (matcher.find()) { final String hostname = matcher.group( 1 ); final int port = Integer.parseInt( matcher.group( 2 ) ); address2Ids.put(new InetSocketAddress( hostname, port ), null); } if (address2Ids.isEmpty()) { throw new IllegalArgumentException("All nodes are also configured as failover nodes," + " this is a configuration failure. In this case, you probably want to leave out the failoverNodes."); } } else { final Matcher matcher = NODE_PATTERN.matcher( memcachedNodes); while (matcher.find()) { final Pair<String, InetSocketAddress> nodeInfo = getRegularNodeDefinition(matcher); address2Ids.put(nodeInfo.getSecond(), nodeInfo.getFirst()); } if (address2Ids.isEmpty()) { throw new IllegalArgumentException("All nodes are also configured as failover nodes," + " this is a configuration failure. In this case, you probably want to leave out the failoverNodes."); } } final List<String> failoverNodeIds = initFailoverNodes(failoverNodes, address2Ids.values()); if(address2Ids.size() == 1 && failoverNodeIds.size() >= 1) { throw new IllegalArgumentException("For a single memcached node there should/must no failoverNodes be specified."); } final NodeIdList primaryNodeIds = new NodeIdList(); for(final Map.Entry<InetSocketAddress, String> address2Id : address2Ids.entrySet()) { final String nodeId = address2Id.getValue(); if (nodeId != null && !failoverNodeIds.contains(nodeId) ) { primaryNodeIds.add(nodeId); } } return new MemcachedNodesManager(memcachedNodes, primaryNodeIds, failoverNodeIds, address2Ids, storageKeyFormat, storageClientCallback); } }
MemcachedNodesManager { @Nonnull public static MemcachedNodesManager createFor(final String memcachedNodes, final String failoverNodes, final StorageKeyFormat storageKeyFormat, final StorageClientCallback storageClientCallback) { if ( memcachedNodes == null || memcachedNodes.trim().isEmpty() ) { throw new IllegalArgumentException("null or empty memcachedNodes not allowed."); } if (memcachedNodes.startsWith("redis: return new MemcachedNodesManager(memcachedNodes, new NodeIdList(), new ArrayList<String>(), new LinkedHashMap<InetSocketAddress, String>(), storageKeyFormat, storageClientCallback); } if ( !NODES_PATTERN.matcher( memcachedNodes ).matches() && !SINGLE_NODE_PATTERN.matcher(memcachedNodes).matches() && !COUCHBASE_BUCKET_NODES_PATTERN.matcher(memcachedNodes).matches()) { throw new IllegalArgumentException( "Configured memcachedNodes attribute has wrong format, must match " + NODES_REGEX ); } final Matcher singleNodeMatcher = SINGLE_NODE_PATTERN.matcher(memcachedNodes); final LinkedHashMap<InetSocketAddress, String> address2Ids = new LinkedHashMap<InetSocketAddress, String>(1); if (singleNodeMatcher.matches()) { address2Ids.put(getSingleShortNodeDefinition(singleNodeMatcher), null); } else if (COUCHBASE_BUCKET_NODES_PATTERN.matcher(memcachedNodes).matches()) { final Matcher matcher = COUCHBASE_BUCKET_NODE_PATTERN.matcher(memcachedNodes); while (matcher.find()) { final String hostname = matcher.group( 1 ); final int port = Integer.parseInt( matcher.group( 2 ) ); address2Ids.put(new InetSocketAddress( hostname, port ), null); } if (address2Ids.isEmpty()) { throw new IllegalArgumentException("All nodes are also configured as failover nodes," + " this is a configuration failure. In this case, you probably want to leave out the failoverNodes."); } } else { final Matcher matcher = NODE_PATTERN.matcher( memcachedNodes); while (matcher.find()) { final Pair<String, InetSocketAddress> nodeInfo = getRegularNodeDefinition(matcher); address2Ids.put(nodeInfo.getSecond(), nodeInfo.getFirst()); } if (address2Ids.isEmpty()) { throw new IllegalArgumentException("All nodes are also configured as failover nodes," + " this is a configuration failure. In this case, you probably want to leave out the failoverNodes."); } } final List<String> failoverNodeIds = initFailoverNodes(failoverNodes, address2Ids.values()); if(address2Ids.size() == 1 && failoverNodeIds.size() >= 1) { throw new IllegalArgumentException("For a single memcached node there should/must no failoverNodes be specified."); } final NodeIdList primaryNodeIds = new NodeIdList(); for(final Map.Entry<InetSocketAddress, String> address2Id : address2Ids.entrySet()) { final String nodeId = address2Id.getValue(); if (nodeId != null && !failoverNodeIds.contains(nodeId) ) { primaryNodeIds.add(nodeId); } } return new MemcachedNodesManager(memcachedNodes, primaryNodeIds, failoverNodeIds, address2Ids, storageKeyFormat, storageClientCallback); } MemcachedNodesManager(final String memcachedNodes, @Nonnull final NodeIdList primaryNodeIds, @Nonnull final List<String> failoverNodeIds,
			@Nonnull final LinkedHashMap<InetSocketAddress, String> address2Ids,
			@Nullable final StorageKeyFormat storageKeyFormat, @Nullable final StorageClientCallback storageClientCallback); }
MemcachedNodesManager { @Nonnull public static MemcachedNodesManager createFor(final String memcachedNodes, final String failoverNodes, final StorageKeyFormat storageKeyFormat, final StorageClientCallback storageClientCallback) { if ( memcachedNodes == null || memcachedNodes.trim().isEmpty() ) { throw new IllegalArgumentException("null or empty memcachedNodes not allowed."); } if (memcachedNodes.startsWith("redis: return new MemcachedNodesManager(memcachedNodes, new NodeIdList(), new ArrayList<String>(), new LinkedHashMap<InetSocketAddress, String>(), storageKeyFormat, storageClientCallback); } if ( !NODES_PATTERN.matcher( memcachedNodes ).matches() && !SINGLE_NODE_PATTERN.matcher(memcachedNodes).matches() && !COUCHBASE_BUCKET_NODES_PATTERN.matcher(memcachedNodes).matches()) { throw new IllegalArgumentException( "Configured memcachedNodes attribute has wrong format, must match " + NODES_REGEX ); } final Matcher singleNodeMatcher = SINGLE_NODE_PATTERN.matcher(memcachedNodes); final LinkedHashMap<InetSocketAddress, String> address2Ids = new LinkedHashMap<InetSocketAddress, String>(1); if (singleNodeMatcher.matches()) { address2Ids.put(getSingleShortNodeDefinition(singleNodeMatcher), null); } else if (COUCHBASE_BUCKET_NODES_PATTERN.matcher(memcachedNodes).matches()) { final Matcher matcher = COUCHBASE_BUCKET_NODE_PATTERN.matcher(memcachedNodes); while (matcher.find()) { final String hostname = matcher.group( 1 ); final int port = Integer.parseInt( matcher.group( 2 ) ); address2Ids.put(new InetSocketAddress( hostname, port ), null); } if (address2Ids.isEmpty()) { throw new IllegalArgumentException("All nodes are also configured as failover nodes," + " this is a configuration failure. In this case, you probably want to leave out the failoverNodes."); } } else { final Matcher matcher = NODE_PATTERN.matcher( memcachedNodes); while (matcher.find()) { final Pair<String, InetSocketAddress> nodeInfo = getRegularNodeDefinition(matcher); address2Ids.put(nodeInfo.getSecond(), nodeInfo.getFirst()); } if (address2Ids.isEmpty()) { throw new IllegalArgumentException("All nodes are also configured as failover nodes," + " this is a configuration failure. In this case, you probably want to leave out the failoverNodes."); } } final List<String> failoverNodeIds = initFailoverNodes(failoverNodes, address2Ids.values()); if(address2Ids.size() == 1 && failoverNodeIds.size() >= 1) { throw new IllegalArgumentException("For a single memcached node there should/must no failoverNodes be specified."); } final NodeIdList primaryNodeIds = new NodeIdList(); for(final Map.Entry<InetSocketAddress, String> address2Id : address2Ids.entrySet()) { final String nodeId = address2Id.getValue(); if (nodeId != null && !failoverNodeIds.contains(nodeId) ) { primaryNodeIds.add(nodeId); } } return new MemcachedNodesManager(memcachedNodes, primaryNodeIds, failoverNodeIds, address2Ids, storageKeyFormat, storageClientCallback); } MemcachedNodesManager(final String memcachedNodes, @Nonnull final NodeIdList primaryNodeIds, @Nonnull final List<String> failoverNodeIds,
			@Nonnull final LinkedHashMap<InetSocketAddress, String> address2Ids,
			@Nullable final StorageKeyFormat storageKeyFormat, @Nullable final StorageClientCallback storageClientCallback); @Nonnull static MemcachedNodesManager createFor(final String memcachedNodes, final String failoverNodes, final StorageKeyFormat storageKeyFormat,
            final StorageClientCallback storageClientCallback); String getMemcachedNodes(); int getCountNodes(); @Nonnull NodeIdList getPrimaryNodeIds(); @Nonnull List<String> getFailoverNodeIds(); boolean isEncodeNodeIdInSessionId(); @Nonnull String getNodeId(final InetSocketAddress socketAddress); @CheckForNull String getNextPrimaryNodeId(final String nodeId); String getNextAvailableNodeId(final String nodeId); @Nonnull SessionIdFormat getSessionIdFormat(); @Nonnull StorageKeyFormat getStorageKeyFormat(); @Nonnull List<InetSocketAddress> getAllMemcachedAddresses(); @Nonnull String createSessionId( @Nonnull final String sessionId ); void setNodeAvailable(@Nullable final String nodeId, final boolean available); boolean isNodeAvailable(final String nodeId); boolean isValidForMemcached(final String sessionId); boolean canHitMemcached(final String sessionId); void onLoadFromMemcachedSuccess(final String sessionId); void onLoadFromMemcachedFailure(final String sessionId); String setNodeAvailableForSessionId(final String sessionId, final boolean available); String getNewSessionIdIfNodeFromSessionIdUnavailable( @Nonnull final String sessionId ); String changeSessionIdForTomcatFailover( @Nonnull final String sessionId, final String jvmRoute ); boolean isCouchbaseBucketConfig(); boolean isRedisConfig(); List<URI> getCouchbaseBucketURIs(); }
MemcachedNodesManager { @Nonnull public static MemcachedNodesManager createFor(final String memcachedNodes, final String failoverNodes, final StorageKeyFormat storageKeyFormat, final StorageClientCallback storageClientCallback) { if ( memcachedNodes == null || memcachedNodes.trim().isEmpty() ) { throw new IllegalArgumentException("null or empty memcachedNodes not allowed."); } if (memcachedNodes.startsWith("redis: return new MemcachedNodesManager(memcachedNodes, new NodeIdList(), new ArrayList<String>(), new LinkedHashMap<InetSocketAddress, String>(), storageKeyFormat, storageClientCallback); } if ( !NODES_PATTERN.matcher( memcachedNodes ).matches() && !SINGLE_NODE_PATTERN.matcher(memcachedNodes).matches() && !COUCHBASE_BUCKET_NODES_PATTERN.matcher(memcachedNodes).matches()) { throw new IllegalArgumentException( "Configured memcachedNodes attribute has wrong format, must match " + NODES_REGEX ); } final Matcher singleNodeMatcher = SINGLE_NODE_PATTERN.matcher(memcachedNodes); final LinkedHashMap<InetSocketAddress, String> address2Ids = new LinkedHashMap<InetSocketAddress, String>(1); if (singleNodeMatcher.matches()) { address2Ids.put(getSingleShortNodeDefinition(singleNodeMatcher), null); } else if (COUCHBASE_BUCKET_NODES_PATTERN.matcher(memcachedNodes).matches()) { final Matcher matcher = COUCHBASE_BUCKET_NODE_PATTERN.matcher(memcachedNodes); while (matcher.find()) { final String hostname = matcher.group( 1 ); final int port = Integer.parseInt( matcher.group( 2 ) ); address2Ids.put(new InetSocketAddress( hostname, port ), null); } if (address2Ids.isEmpty()) { throw new IllegalArgumentException("All nodes are also configured as failover nodes," + " this is a configuration failure. In this case, you probably want to leave out the failoverNodes."); } } else { final Matcher matcher = NODE_PATTERN.matcher( memcachedNodes); while (matcher.find()) { final Pair<String, InetSocketAddress> nodeInfo = getRegularNodeDefinition(matcher); address2Ids.put(nodeInfo.getSecond(), nodeInfo.getFirst()); } if (address2Ids.isEmpty()) { throw new IllegalArgumentException("All nodes are also configured as failover nodes," + " this is a configuration failure. In this case, you probably want to leave out the failoverNodes."); } } final List<String> failoverNodeIds = initFailoverNodes(failoverNodes, address2Ids.values()); if(address2Ids.size() == 1 && failoverNodeIds.size() >= 1) { throw new IllegalArgumentException("For a single memcached node there should/must no failoverNodes be specified."); } final NodeIdList primaryNodeIds = new NodeIdList(); for(final Map.Entry<InetSocketAddress, String> address2Id : address2Ids.entrySet()) { final String nodeId = address2Id.getValue(); if (nodeId != null && !failoverNodeIds.contains(nodeId) ) { primaryNodeIds.add(nodeId); } } return new MemcachedNodesManager(memcachedNodes, primaryNodeIds, failoverNodeIds, address2Ids, storageKeyFormat, storageClientCallback); } MemcachedNodesManager(final String memcachedNodes, @Nonnull final NodeIdList primaryNodeIds, @Nonnull final List<String> failoverNodeIds,
			@Nonnull final LinkedHashMap<InetSocketAddress, String> address2Ids,
			@Nullable final StorageKeyFormat storageKeyFormat, @Nullable final StorageClientCallback storageClientCallback); @Nonnull static MemcachedNodesManager createFor(final String memcachedNodes, final String failoverNodes, final StorageKeyFormat storageKeyFormat,
            final StorageClientCallback storageClientCallback); String getMemcachedNodes(); int getCountNodes(); @Nonnull NodeIdList getPrimaryNodeIds(); @Nonnull List<String> getFailoverNodeIds(); boolean isEncodeNodeIdInSessionId(); @Nonnull String getNodeId(final InetSocketAddress socketAddress); @CheckForNull String getNextPrimaryNodeId(final String nodeId); String getNextAvailableNodeId(final String nodeId); @Nonnull SessionIdFormat getSessionIdFormat(); @Nonnull StorageKeyFormat getStorageKeyFormat(); @Nonnull List<InetSocketAddress> getAllMemcachedAddresses(); @Nonnull String createSessionId( @Nonnull final String sessionId ); void setNodeAvailable(@Nullable final String nodeId, final boolean available); boolean isNodeAvailable(final String nodeId); boolean isValidForMemcached(final String sessionId); boolean canHitMemcached(final String sessionId); void onLoadFromMemcachedSuccess(final String sessionId); void onLoadFromMemcachedFailure(final String sessionId); String setNodeAvailableForSessionId(final String sessionId, final boolean available); String getNewSessionIdIfNodeFromSessionIdUnavailable( @Nonnull final String sessionId ); String changeSessionIdForTomcatFailover( @Nonnull final String sessionId, final String jvmRoute ); boolean isCouchbaseBucketConfig(); boolean isRedisConfig(); List<URI> getCouchbaseBucketURIs();  }