Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.openqa.selenium.grid.data;
import static com.google.common.collect.ImmutableList.toImmutableList;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.ImmutableCapabilities;
import org.openqa.selenium.json.JsonException;
import org.openqa.selenium.remote.SessionId;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
public class NodeStatus {
private final UUID nodeId;
private final URI externalUri;
private final int maxSessionCount;
private final Map stereotypes;
private final Set snapshot;
public NodeStatus(
UUID nodeId,
URI externalUri,
int maxSessionCount,
Map stereotypes,
Collection snapshot) {
this.nodeId = Objects.requireNonNull(nodeId);
this.externalUri = Objects.requireNonNull(externalUri);
Preconditions.checkArgument(maxSessionCount > 0, "Max session count must be greater than 0.");
this.maxSessionCount = maxSessionCount;
this.stereotypes = ImmutableMap.copyOf(Objects.requireNonNull(stereotypes));
this.snapshot = ImmutableSet.copyOf(Objects.requireNonNull(snapshot));
}
public boolean hasCapacity() {
return !stereotypes.isEmpty();
}
public boolean hasCapacity(Capabilities caps) {
return stereotypes.getOrDefault(caps, 0) > 0;
}
public UUID getNodeId() {
return nodeId;
}
public URI getUri() {
return externalUri;
}
public int getMaxSessionCount() {
return maxSessionCount;
}
public Map getStereotypes() {
return stereotypes;
}
public Set getCurrentSessions() {
return snapshot;
}
@Override
public boolean equals(Object o) {
if (!(o instanceof NodeStatus)) {
return false;
}
NodeStatus that = (NodeStatus) o;
return Objects.equals(this.nodeId, that.nodeId) &&
Objects.equals(this.externalUri, that.externalUri) &&
this.maxSessionCount == that.maxSessionCount &&
Objects.equals(this.stereotypes, that.stereotypes) &&
Objects.equals(this.snapshot, that.snapshot);
}
@Override
public int hashCode() {
return Objects.hash(nodeId, externalUri, maxSessionCount, stereotypes, snapshot);
}
private Map toJson() {
return ImmutableMap.of(
"id", nodeId,
"uri", externalUri,
"maxSessions", maxSessionCount,
"stereotypes", asCapacity(stereotypes),
"sessions", snapshot);
}
private List