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 Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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.apache.brooklyn.entity.machine.pool;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.location.Location;
import org.apache.brooklyn.api.location.LocationDefinition;
import org.apache.brooklyn.api.location.LocationRegistry;
import org.apache.brooklyn.api.location.LocationSpec;
import org.apache.brooklyn.api.location.MachineLocation;
import org.apache.brooklyn.api.location.NoMachinesAvailableException;
import org.apache.brooklyn.api.mgmt.LocationManager;
import org.apache.brooklyn.api.mgmt.Task;
import org.apache.brooklyn.api.policy.PolicySpec;
import org.apache.brooklyn.api.sensor.AttributeSensor;
import org.apache.brooklyn.config.ConfigKey;
import org.apache.brooklyn.core.config.ConfigKeys;
import org.apache.brooklyn.core.effector.Effectors;
import org.apache.brooklyn.core.entity.Attributes;
import org.apache.brooklyn.core.entity.EntityInternal;
import org.apache.brooklyn.core.entity.lifecycle.Lifecycle;
import org.apache.brooklyn.core.entity.trait.Startable;
import org.apache.brooklyn.core.location.Machines;
import org.apache.brooklyn.core.location.dynamic.DynamicLocation;
import org.apache.brooklyn.core.mgmt.internal.LocalLocationManager;
import org.apache.brooklyn.core.location.dynamic.LocationOwner;
import org.apache.brooklyn.core.sensor.Sensors;
import org.apache.brooklyn.entity.group.AbstractMembershipTrackingPolicy;
import org.apache.brooklyn.entity.group.DynamicClusterImpl;
import org.apache.brooklyn.util.collections.MutableMap;
import org.apache.brooklyn.util.core.task.DynamicTasks;
import org.apache.brooklyn.util.guava.Maybe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.reflect.TypeToken;
/**
* The normal usage pattern is to instantiate this entity to create your cluster, which will
* automatically create a {@link ServerPoolLocation}. The location can be looked up from the
* {@link LocationRegistry} (e.g. {@code mgmt.getLocationRegistry().resolve("my-pool-name")}),
* which uses the {@link ServerPoolLocationResolver}.
*
* Each location delegates to the associated {@link ServerPool} to claim machines (which are
* provisioned as required), and to release machines back to the pool.
*
* This differs from Clocker's use of {@link DynamicLocation} in that the ServerPool has multiple
* locations. This makes the use of {@link LocationOwner} a little confusing
* (e.g. {@link LocationOwner#DYNAMIC_LOCATION} is not set).
*/
public class ServerPoolImpl extends DynamicClusterImpl implements ServerPool {
private static final Logger LOG = LoggerFactory.getLogger(ServerPoolImpl.class);
private static enum MachinePoolMemberStatus {
/** The server is available for use */
AVAILABLE,
/** The server has been leased to another application */
CLAIMED,
/**
* The server will not be leased to other applications. It will be the first
* candidate to release when the pool is shrunk.
*/
UNUSABLE
}
private static final AttributeSensor SERVER_STATUS = Sensors.newSensor(MachinePoolMemberStatus.class,
"pool.serverStatus", "The status of an entity in the pool");
// The sensors here would be better as private fields but there's not really a
// good way to manage their state when rebinding.
/** Accesses must be synchronised by mutex */
// Would use BiMap but persisting them tends to throw ConcurrentModificationExceptions.
@SuppressWarnings("serial")
public static final AttributeSensor