blob: 7f7dc6157d739fdb2f31bd9a6f8c8efd8f1230fd [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2009, 2020 Stephan Wahlbrink and others.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors:
# Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
#=============================================================================*/
package org.eclipse.statet.rj.servi.pool;
import org.eclipse.statet.jcommons.lang.NonNullByDefault;
import org.eclipse.statet.jcommons.lang.Nullable;
import org.eclipse.statet.jcommons.rmi.RMIAddress;
import org.eclipse.statet.internal.rj.servi.NodeHandler;
import org.eclipse.statet.rj.RjException;
@NonNullByDefault
public class PoolNodeItem {
private final PoolNodeObject nodeObj;
private long creationTime;
private PoolNodeState state;
private long stateTime;
private long usageCount;
private long usageDuration;
private @Nullable RMIAddress address;
private @Nullable String clientLabel;
public PoolNodeItem(final PoolNodeObject nodeObj, final long stamp) {
synchronized(nodeObj) {
this.nodeObj= nodeObj;
this.creationTime= nodeObj.getCreationTime();
this.state= nodeObj.getState();
this.stateTime= nodeObj.getStateTime();
this.usageCount= nodeObj.getAllocatedCount();
this.usageDuration= nodeObj.getAllocatedDuration();
// if (this.state == PoolNodeState.ALLOCATED) {
// this.usageDuration+= Math.min(stamp - this.stateTime, 0L);
// }
final NodeHandler nodeHandler= nodeObj.getNodeHandler();
this.address= (nodeHandler != null) ? nodeHandler.getAddress() : null;
this.clientLabel= nodeObj.getClientLabel();
}
}
public long getCreationTime() {
return this.creationTime;
}
public PoolNodeState getState() {
return this.state;
}
public long getStateTime() {
return this.stateTime;
}
public @Nullable String getCurrentClientLabel() {
return this.clientLabel;
}
public long getUsageCount() {
return this.usageCount;
}
public long getUsageDuration() {
return this.usageDuration;
}
public boolean isConsoleEnabled() {
final NodeHandler nodeHandler= this.nodeObj.getNodeHandler();
return (nodeHandler != null && nodeHandler.isConsoleEnabled());
}
public void enableConsole(final String authConfig) throws RjException {
final NodeHandler nodeHandler= this.nodeObj.getNodeHandler();
if (nodeHandler != null) {
nodeHandler.enableConsole(authConfig);
}
}
public void disableConsole() throws RjException {
final NodeHandler nodeHandler= this.nodeObj.getNodeHandler();
if (nodeHandler != null) {
nodeHandler.disableConsole();
}
}
/**
* Returns the RMI address of the node.
*
* @return the address of the node if available, otherwise <code>null</code>
*
* @since 2.0
*/
public @Nullable RMIAddress getAddress() {
return this.address;
}
/**
* Evicts the pool item.
*
* The specified timeout is used when the node is in use.
*
* @param timeoutMillis the timeout in milliseconds
*
* @since 2.0
*/
public void evict(final long timeoutMillis) {
if (this.nodeObj != null) {
this.nodeObj.evict(timeoutMillis);
}
}
}