org.apache.commons.collections4.list.UnmodifiableList Java Examples
The following examples show how to use
org.apache.commons.collections4.list.UnmodifiableList.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LocationCache.java From azure-cosmosdb-java with MIT License | 6 votes |
private UnmodifiableMap<String, URL> getEndpointByLocation(Iterable<DatabaseAccountLocation> locations, Utils.ValueHolder<UnmodifiableList<String>> orderedLocations) { Map<String, URL> endpointsByLocation = new CaseInsensitiveMap<>(); List<String> parsedLocations = new ArrayList<>(); for (DatabaseAccountLocation location: locations) { if (!Strings.isNullOrEmpty(location.getName())) { try { URL endpoint = new URL(location.getEndpoint().toLowerCase()); endpointsByLocation.put(location.getName().toLowerCase(), endpoint); parsedLocations.add(location.getName()); } catch (Exception e) { logger.warn("GetAvailableEndpointsByLocation() - skipping add for location = [{}] as it is location name is either empty or endpoint is malformed [{}]", location.getName(), location.getEndpoint()); } } } orderedLocations.v = new UnmodifiableList(parsedLocations); return (UnmodifiableMap) UnmodifiableMap.unmodifiableMap(endpointsByLocation); }
Example #2
Source File: LocationCache.java From azure-cosmosdb-java with MIT License | 5 votes |
/** * Gets list of write endpoints ordered by * 1. Preferred location * 2. Endpoint availability * @return */ public UnmodifiableList<URL> getWriteEndpoints() { if (this.locationUnavailabilityInfoByEndpoint.size() > 0 && unavailableLocationsExpirationTimePassed()) { this.updateLocationCache(); } return this.locationInfo.writeEndpoints; }
Example #3
Source File: SerializationPostInstrumentationPass.java From coroutines with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void pass(ClassNode classNode, InstrumentationState state) { Validate.notNull(classNode); Validate.notNull(state); // Methods attributes should be assigned at this point. Validate.validState(!state.methodAttributes().isEmpty()); Validate.validState(state.methodAttributes().keySet().stream().allMatch(x -> x != null)); Validate.validState(state.methodAttributes().values().stream().allMatch(x -> x != null)); // Sanity check to make sure that we're only dealing with methodnodes in the classnode -- this should never trigger unless previous // passes mess up Validate.validState(classNode.methods.containsAll(state.methodAttributes().keySet())); // Generate the fields needed by the serializer/deserializer for (Map.Entry<MethodNode, MethodAttributes> method : state.methodAttributes().entrySet()) { MethodAttributes methodAttrs = method.getValue(); UnmodifiableList<ContinuationPoint> continuationPoints = methodAttrs.getContinuationPoints(); // Shove in versioning info for the method as a fields on the class. int methodId = methodAttrs.getSignature().getMethodId(); for (int i = 0; i < continuationPoints.size(); i++) { int continuationPointId = i; FieldNode methodIdField = new FieldNode( INSTRUMENTED_METHODID_FIELD_ACCESS, getIdentifyingFieldName(methodId, continuationPointId), INSTRUMENTED_METHODID_FIELD_TYPE.getDescriptor(), null, INSTRUMENTED_METHODID_FIELD_VALUE); classNode.fields.add(methodIdField); } } }
Example #4
Source File: MethodAttributes.java From coroutines with GNU Lesser General Public License v3.0 | 5 votes |
MethodAttributes( MethodSignature signature, InstrumentationSettings settings, List<ContinuationPoint> continuationPoints, List<SynchronizationPoint> synchPoints, CoreVariables coreVars, CacheVariables cacheVars, StorageContainerVariables storageContainerVars, StorageVariables localsStorageVars, StorageVariables stackStorageVars, LockVariables lockVars) { Validate.notNull(signature); Validate.notNull(settings); Validate.notNull(continuationPoints); Validate.notNull(synchPoints); Validate.notNull(coreVars); Validate.notNull(cacheVars); Validate.notNull(storageContainerVars); Validate.notNull(localsStorageVars); Validate.notNull(stackStorageVars); Validate.notNull(lockVars); Validate.noNullElements(continuationPoints); Validate.noNullElements(synchPoints); this.signature = signature; this.settings = settings; this.continuationPoints = (UnmodifiableList<ContinuationPoint>) UnmodifiableList.unmodifiableList(new ArrayList<>(continuationPoints)); this.synchPoints = (UnmodifiableList<SynchronizationPoint>) UnmodifiableList.unmodifiableList(new ArrayList<>(synchPoints)); this.coreVars = coreVars; this.cacheVars = cacheVars; this.storageContainerVars = storageContainerVars; this.localsStorageVars = localsStorageVars; this.stackStorageVars = stackStorageVars; this.lockVars = lockVars; }
Example #5
Source File: SystemInfo.java From app-runner with MIT License | 5 votes |
public SystemInfo(String hostName, String user, Long pid, List<String> publicKeys, String osName, int numCpus) { this.hostName = hostName; this.user = user; this.pid = pid; this.publicKeys = new UnmodifiableList<>(publicKeys); this.osName = osName; this.numCpus = numCpus; }
Example #6
Source File: GlobalAddressResolverTest.java From azure-cosmosdb-java with MIT License | 5 votes |
@BeforeClass(groups = "unit") public void setup() throws Exception { urlforRead1 = new URL("http://testRead1.com/"); urlforRead2 = new URL("http://testRead2.com/"); urlforRead3 = new URL("http://testRead3.com/"); urlforWrite1 = new URL("http://testWrite1.com/"); urlforWrite2 = new URL("http://testWrite2.com/"); urlforWrite3 = new URL("http://testWrite3.com/"); connectionPolicy = new ConnectionPolicy(); connectionPolicy.setEnableReadRequestsFallback(true); httpClient = Mockito.mock(CompositeHttpClient.class); endpointManager = Mockito.mock(GlobalEndpointManager.class); List<URL> readEndPointList = new ArrayList<>(); readEndPointList.add(urlforRead1); readEndPointList.add(urlforRead2); readEndPointList.add(urlforRead3); UnmodifiableList readList = new UnmodifiableList(readEndPointList); List<URL> writeEndPointList = new ArrayList<>(); writeEndPointList.add(urlforWrite1); writeEndPointList.add(urlforWrite2); writeEndPointList.add(urlforWrite3); UnmodifiableList writeList = new UnmodifiableList(writeEndPointList); Mockito.when(endpointManager.getReadEndpoints()).thenReturn(readList); Mockito.when(endpointManager.getWriteEndpoints()).thenReturn(writeList); authorizationTokenProvider = Mockito.mock(IAuthorizationTokenProvider.class); DocumentCollection collectionDefinition = new DocumentCollection(); collectionDefinition.setId(UUID.randomUUID().toString()); collectionCache = Mockito.mock(RxCollectionCache.class); Mockito.when(collectionCache.resolveCollectionAsync(Matchers.any(RxDocumentServiceRequest.class))).thenReturn(Single.just(collectionDefinition)); routingMapProvider = Mockito.mock(RxPartitionKeyRangeCache.class); userAgentContainer = Mockito.mock(UserAgentContainer.class); serviceConfigReader = Mockito.mock(GatewayServiceConfigurationReader.class); }
Example #7
Source File: LocationCacheTest.java From azure-cosmosdb-java with MIT License | 5 votes |
private void initialize( boolean useMultipleWriteLocations, boolean enableEndpointDiscovery, boolean isPreferredLocationsListEmpty) throws Exception { this.mockedClient = new DatabaseAccountManagerInternalMock(); this.databaseAccount = LocationCacheTest.createDatabaseAccount(useMultipleWriteLocations); this.preferredLocations = isPreferredLocationsListEmpty ? new UnmodifiableList<>(Collections.emptyList()) : new UnmodifiableList<>(ImmutableList.of("location1", "location2", "location3")); this.cache = new LocationCache( this.preferredLocations, LocationCacheTest.DefaultEndpoint, enableEndpointDiscovery, useMultipleWriteLocations, configs); this.cache.onDatabaseAccountRead(this.databaseAccount); ConnectionPolicy connectionPolicy = new ConnectionPolicy(); connectionPolicy.setEnableEndpointDiscovery(enableEndpointDiscovery); BridgeInternal.setUseMultipleWriteLocations(connectionPolicy, useMultipleWriteLocations); connectionPolicy.setPreferredLocations(this.preferredLocations); this.endpointManager = new GlobalEndpointManager(mockedClient, connectionPolicy, configs); }
Example #8
Source File: ClientRetryPolicy.java From azure-cosmosdb-java with MIT License | 5 votes |
private ShouldRetryResult shouldRetryOnSessionNotAvailable() { this.sessionTokenRetryCount++; if (!this.enableEndpointDiscovery) { // if endpoint discovery is disabled, the request cannot be retried anywhere else return ShouldRetryResult.noRetry(); } else { if (this.canUseMultipleWriteLocations) { UnmodifiableList<URL> endpoints = this.isReadRequest ? this.globalEndpointManager.getReadEndpoints() : this.globalEndpointManager.getWriteEndpoints(); if (this.sessionTokenRetryCount > endpoints.size()) { // When use multiple write locations is true and the request has been tried // on all locations, then don't retry the request return ShouldRetryResult.noRetry(); } else { this.retryContext = new RetryContext(this.sessionTokenRetryCount - 1, this.sessionTokenRetryCount > 1); return ShouldRetryResult.retryAfter(Duration.ZERO); } } else { if (this.sessionTokenRetryCount > 1) { // When cannot use multiple write locations, then don't retry the request if // we have already tried this request on the write location return ShouldRetryResult.noRetry(); } else { this.retryContext = new RetryContext(this.sessionTokenRetryCount - 1, false); return ShouldRetryResult.retryAfter(Duration.ZERO); } } } }
Example #9
Source File: LocationCache.java From azure-cosmosdb-java with MIT License | 5 votes |
public DatabaseAccountLocationsInfo(List<String> preferredLocations, URL defaultEndpoint) { this.preferredLocations = new UnmodifiableList<>(preferredLocations.stream().map(loc -> loc.toLowerCase()).collect(Collectors.toList())); this.availableWriteEndpointByLocation = (UnmodifiableMap) UnmodifiableMap.unmodifiableMap(new CaseInsensitiveMap<>()); this.availableReadEndpointByLocation = (UnmodifiableMap) UnmodifiableMap.unmodifiableMap(new CaseInsensitiveMap<>()); this.availableReadLocations = new UnmodifiableList<>(Collections.emptyList()); this.availableWriteLocations = new UnmodifiableList<>(Collections.emptyList()); this.readEndpoints = new UnmodifiableList<>(Collections.singletonList(defaultEndpoint)); this.writeEndpoints = new UnmodifiableList<>(Collections.singletonList(defaultEndpoint)); }
Example #10
Source File: LocationCache.java From azure-cosmosdb-java with MIT License | 5 votes |
/** * Resolves request to service endpoint. * 1. If this is a write request * (a) If UseMultipleWriteLocations = true * (i) For document writes, resolve to most preferred and available write endpoint. * Once the endpoint is marked unavailable, it is moved to the end of available write endpoint. Current request will * be retried on next preferred available write endpoint. * (ii) For all other resources, always resolve to first/second (regardless of preferred locations) * write endpoint in {@link DatabaseAccount#getWritableLocations()}. * Endpoint of first write location in {@link DatabaseAccount#getWritableLocations()} is the only endpoint that supports * write operation on all resource types (except during that region's failover). * Only during manual failover, client would retry write on second write location in {@link DatabaseAccount#getWritableLocations()}. * (b) Else resolve the request to first write endpoint in {@link DatabaseAccount#getWritableLocations()} OR * second write endpoint in {@link DatabaseAccount#getWritableLocations()} in case of manual failover of that location. * 2. Else resolve the request to most preferred available read endpoint (automatic failover for read requests) * @param request Request for which endpoint is to be resolved * @return Resolved endpoint */ public URL resolveServiceEndpoint(RxDocumentServiceRequest request) { if(request.requestContext != null && request.requestContext.locationEndpointToRoute != null) { return request.requestContext.locationEndpointToRoute; } int locationIndex = Utils.getValueOrDefault(request.requestContext.locationIndexToRoute, 0); boolean usePreferredLocations = request.requestContext.usePreferredLocations != null ? request.requestContext.usePreferredLocations : true; if(!usePreferredLocations || (request.getOperationType().isWriteOperation() && !this.canUseMultipleWriteLocations(request))) { // For non-document resource types in case of client can use multiple write locations // or when client cannot use multiple write locations, flip-flop between the // first and the second writable region in DatabaseAccount (for manual failover) DatabaseAccountLocationsInfo currentLocationInfo = this.locationInfo; if(this.enableEndpointDiscovery && currentLocationInfo.availableWriteLocations.size() > 0) { locationIndex = Math.min(locationIndex%2, currentLocationInfo.availableWriteLocations.size()-1); String writeLocation = currentLocationInfo.availableWriteLocations.get(locationIndex); return currentLocationInfo.availableWriteEndpointByLocation.get(writeLocation); } else { return this.defaultEndpoint; } } else { UnmodifiableList<URL> endpoints = request.getOperationType().isWriteOperation()? this.getWriteEndpoints() : this.getReadEndpoints(); return endpoints.get(locationIndex % endpoints.size()); } }
Example #11
Source File: LocationCache.java From azure-cosmosdb-java with MIT License | 5 votes |
/** * Gets list of read endpoints ordered by * * 1. Preferred location * 2. Endpoint availability * @return */ public UnmodifiableList<URL> getReadEndpoints() { if (this.locationUnavailabilityInfoByEndpoint.size() > 0 && unavailableLocationsExpirationTimePassed()) { this.updateLocationCache(); } return this.locationInfo.readEndpoints; }
Example #12
Source File: GlobalEndpointManager.java From azure-cosmosdb-java with MIT License | 4 votes |
public UnmodifiableList<URL> getWriteEndpoints() { //readonly return this.locationCache.getWriteEndpoints(); }
Example #13
Source File: GlobalEndpointManager.java From azure-cosmosdb-java with MIT License | 4 votes |
public UnmodifiableList<URL> getReadEndpoints() { // readonly return this.locationCache.getReadEndpoints(); }
Example #14
Source File: LocationCacheTest.java From azure-cosmosdb-java with MIT License | 4 votes |
private void validateLocationCacheAsync( boolean useMultipleWriteLocations, boolean endpointDiscoveryEnabled, boolean isPreferredListEmpty) throws Exception { for (int writeLocationIndex = 0; writeLocationIndex < 3; writeLocationIndex++) { for (int readLocationIndex = 0; readLocationIndex < 2; readLocationIndex++) { this.initialize( useMultipleWriteLocations, endpointDiscoveryEnabled, isPreferredListEmpty); UnmodifiableList<URL> currentWriteEndpoints = this.cache.getWriteEndpoints(); UnmodifiableList<URL> currentReadEndpoints = this.cache.getReadEndpoints(); for (int i = 0; i < readLocationIndex; i++) { this.cache.markEndpointUnavailableForRead(createUrl(Iterables.get(this.databaseAccount.getReadableLocations(), i).getEndpoint())); this.endpointManager.markEndpointUnavailableForRead(createUrl(Iterables.get(this.databaseAccount.getReadableLocations(), i).getEndpoint()));; } for (int i = 0; i < writeLocationIndex; i++) { this.cache.markEndpointUnavailableForWrite(createUrl(Iterables.get(this.databaseAccount.getWritableLocations(), i).getEndpoint())); this.endpointManager.markEndpointUnavailableForWrite(createUrl(Iterables.get(this.databaseAccount.getWritableLocations(), i).getEndpoint())); } Map<String, URL> writeEndpointByLocation = toStream(this.databaseAccount.getWritableLocations()) .collect(Collectors.toMap(i -> i.getName(), i -> createUrl(i.getEndpoint()))); Map<String, URL> readEndpointByLocation = toStream(this.databaseAccount.getReadableLocations()) .collect(Collectors.toMap(i -> i.getName(), i -> createUrl(i.getEndpoint()))); URL[] preferredAvailableWriteEndpoints = toStream(this.preferredLocations).skip(writeLocationIndex) .filter(location -> writeEndpointByLocation.containsKey(location)) .map(location -> writeEndpointByLocation.get(location)) .collect(Collectors.toList()).toArray(new URL[0]); URL[] preferredAvailableReadEndpoints = toStream(this.preferredLocations).skip(readLocationIndex) .filter(location -> readEndpointByLocation.containsKey(location)) .map(location -> readEndpointByLocation.get(location)) .collect(Collectors.toList()).toArray(new URL[0]); this.validateEndpointRefresh( useMultipleWriteLocations, endpointDiscoveryEnabled, preferredAvailableWriteEndpoints, preferredAvailableReadEndpoints, readLocationIndex > 0 && !currentReadEndpoints.get(0).equals(DefaultEndpoint), writeLocationIndex > 0, currentReadEndpoints.size() > 1, currentWriteEndpoints.size() > 1 ); this.validateGlobalEndpointLocationCacheRefreshAsync(); this.validateRequestEndpointResolution( useMultipleWriteLocations, endpointDiscoveryEnabled, preferredAvailableWriteEndpoints, preferredAvailableReadEndpoints); // wait for TTL on unavailability info TimeUnit.SECONDS.sleep(configs.getUnavailableLocationsExpirationTimeInSeconds() + 1); assertThat(currentWriteEndpoints.toArray()).containsExactly(this.cache.getWriteEndpoints().toArray()); assertThat(currentReadEndpoints.toArray()).containsExactly(this.cache.getReadEndpoints().toArray()); } } }
Example #15
Source File: LocationCacheTest.java From azure-cosmosdb-java with MIT License | 4 votes |
private void validateRequestEndpointResolution( boolean useMultipleWriteLocations, boolean endpointDiscoveryEnabled, URL[] availableWriteEndpoints, URL[] availableReadEndpoints) throws MalformedURLException { URL firstAvailableWriteEndpoint; URL secondAvailableWriteEndpoint; if (!endpointDiscoveryEnabled) { firstAvailableWriteEndpoint = LocationCacheTest.DefaultEndpoint; secondAvailableWriteEndpoint = LocationCacheTest.DefaultEndpoint; } else if (!useMultipleWriteLocations) { firstAvailableWriteEndpoint = createUrl(Iterables.get(this.databaseAccount.getWritableLocations(), 0).getEndpoint()); secondAvailableWriteEndpoint = createUrl(Iterables.get(this.databaseAccount.getWritableLocations(), 1).getEndpoint()); } else if (availableWriteEndpoints.length > 1) { firstAvailableWriteEndpoint = availableWriteEndpoints[0]; secondAvailableWriteEndpoint = availableWriteEndpoints[1]; } else if (availableWriteEndpoints.length > 0) { firstAvailableWriteEndpoint = availableWriteEndpoints[0]; Iterator<DatabaseAccountLocation> writeLocationsIterator = databaseAccount.getWritableLocations().iterator(); String writeEndpoint = writeLocationsIterator.next().getEndpoint(); secondAvailableWriteEndpoint = writeEndpoint != firstAvailableWriteEndpoint.toString() ? new URL(writeEndpoint) : new URL(writeLocationsIterator.next().getEndpoint()); } else { firstAvailableWriteEndpoint = LocationCacheTest.DefaultEndpoint; secondAvailableWriteEndpoint = LocationCacheTest.DefaultEndpoint; } URL firstAvailableReadEndpoint; if (!endpointDiscoveryEnabled) { firstAvailableReadEndpoint = LocationCacheTest.DefaultEndpoint; } else if (this.preferredLocations.size() == 0) { firstAvailableReadEndpoint = firstAvailableWriteEndpoint; } else if (availableReadEndpoints.length > 0) { firstAvailableReadEndpoint = availableReadEndpoints[0]; } else { firstAvailableReadEndpoint = LocationCacheTest.EndpointByLocation.get(this.preferredLocations.get(0)); } URL firstWriteEnpoint = !endpointDiscoveryEnabled ? LocationCacheTest.DefaultEndpoint : createUrl(Iterables.get(this.databaseAccount.getWritableLocations(), 0).getEndpoint()); URL secondWriteEnpoint = !endpointDiscoveryEnabled ? LocationCacheTest.DefaultEndpoint : createUrl(Iterables.get(this.databaseAccount.getWritableLocations(), 1).getEndpoint()); // If current write endpoint is unavailable, write endpoints order doesn't change // All write requests flip-flop between current write and alternate write endpoint UnmodifiableList<URL> writeEndpoints = this.cache.getWriteEndpoints(); assertThat(firstAvailableWriteEndpoint).isEqualTo(writeEndpoints.get(0)); assertThat(secondAvailableWriteEndpoint).isEqualTo(this.resolveEndpointForWriteRequest(ResourceType.Document, true)); assertThat(firstAvailableWriteEndpoint).isEqualTo(this.resolveEndpointForWriteRequest(ResourceType.Document, false)); // Writes to other resource types should be directed to first/second write endpoint assertThat(firstWriteEnpoint).isEqualTo(this.resolveEndpointForWriteRequest(ResourceType.Database, false)); assertThat(secondWriteEnpoint).isEqualTo(this.resolveEndpointForWriteRequest(ResourceType.Database, true)); // Reads should be directed to available read endpoints regardless of resource type assertThat(firstAvailableReadEndpoint).isEqualTo(this.resolveEndpointForReadRequest(true)); assertThat(firstAvailableReadEndpoint).isEqualTo(this.resolveEndpointForReadRequest(false)); }
Example #16
Source File: SerializationDetailer.java From coroutines with GNU Lesser General Public License v3.0 | 4 votes |
public void detail(MethodNode methodNode, MethodAttributes attrs, StringBuilder output) { Validate.notNull(methodNode); Validate.notNull(attrs); Validate.notNull(output); int methodId = attrs.getSignature().getMethodId(); output.append("Class Name: ").append(attrs.getSignature().getClassName().replace('/', '.')).append('\n'); output.append("Method Name: ").append(attrs.getSignature().getMethodName()).append('\n'); output.append("Method Params: ").append(attrs.getSignature().getMethodDescriptor()).append('\n'); output.append("Method Return: ").append(attrs.getSignature().getReturnType()).append('\n'); output.append("Method ID: ").append(methodId).append('\n'); output.append("------------------------------------\n"); UnmodifiableList<ContinuationPoint> cps = attrs.getContinuationPoints(); for (int i = 0; i < cps.size(); i++) { ContinuationPoint cp = cps.get(i); int line = cp.getLineNumber() == null ? -1 : cp.getLineNumber(); String header = String.format("Continuation Point ID: %-4d Line: %-4d Type: %s", i, line, cp.getClass().getSimpleName()); output.append(header).append('\n'); // Check out PackStateGenerators class for how things are organized. Brief overview follows... // container[0] has local variables that are bytes/shorts/ints // container[1] has local variables that are floats // container[2] has local variables that are longs // container[3] has local variables that are doubles // container[4] has local variables that are Objects // container[5] has operands that are bytes/shorts/ints // container[6] has operands that are floats // container[7] has operands that are longs // container[8] has operands that are doubles // container[9] has operands that are Objects detailLocals(cp, methodNode, output); detailOperands(cp, output); output.append('\n'); } output.append('\n'); }
Example #17
Source File: LocationCache.java From azure-cosmosdb-java with MIT License | 4 votes |
void onLocationPreferenceChanged(UnmodifiableList<String> preferredLocations) { this.updateLocationCache( null, null , preferredLocations, null); }
Example #18
Source File: MethodAttributes.java From coroutines with GNU Lesser General Public License v3.0 | 4 votes |
public UnmodifiableList<ContinuationPoint> getContinuationPoints() { return continuationPoints; }
Example #19
Source File: MethodAttributes.java From coroutines with GNU Lesser General Public License v3.0 | 4 votes |
public UnmodifiableList<SynchronizationPoint> getSynchronizationPoints() { return synchPoints; }
Example #20
Source File: Dn.java From directory-ldap-api with Apache License 2.0 | 2 votes |
/** * Retrieves all the components of this name. * * @return All the components */ public List<Rdn> getRdns() { return UnmodifiableList.unmodifiableList( rdns ); }
Example #21
Source File: CompositeClassInformationRepository.java From coroutines with GNU Lesser General Public License v3.0 | 2 votes |
/** * Constructs a {@link ClassLoaderClassInformationRepository} object. * @param repos class information repositories * @throws NullPointerException if any argument is {@code null} * @throws IllegalArgumentException if {@code repos} contains {@code null} */ public CompositeClassInformationRepository(ClassInformationRepository... repos) { Validate.notNull(repos); Validate.noNullElements(repos); this.repos = (UnmodifiableList<ClassInformationRepository>) unmodifiableList(new ArrayList<>(asList(repos))); }