All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.cassandra.dht.tokenallocator.TokenAllocatorEvent Maven / Gradle / Ivy

Go to download

The Apache Cassandra Project develops a highly scalable second-generation distributed database, bringing together Dynamo's fully distributed design and Bigtable's ColumnFamily-based data model.

There is a newer version: 5.0.0
Show newest version
/*
 * 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.cassandra.dht.tokenallocator;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;

import org.apache.cassandra.dht.Token;
import org.apache.cassandra.dht.tokenallocator.TokenAllocatorBase.TokenInfo;
import org.apache.cassandra.dht.tokenallocator.TokenAllocatorBase.UnitInfo;
import org.apache.cassandra.dht.tokenallocator.TokenAllocatorBase.Weighted;
import org.apache.cassandra.diag.DiagnosticEvent;

/**
 * DiagnosticEvent implementation for {@link TokenAllocator} activities.
 */
final class TokenAllocatorEvent extends DiagnosticEvent
{

    private final TokenAllocatorEventType type;
    private final TokenAllocatorBase allocator;
    private final int replicas;
    @Nullable
    private final Integer numTokens;
    @Nullable
    private final Collection> sortedUnits;
    @Nullable
    private final Map> unitToTokens;
    @Nullable
    private final ImmutableMap sortedTokens;
    @Nullable
    private final List tokens;
    @Nullable
    private final Unit unit;
    @Nullable
    private final TokenInfo tokenInfo;

    TokenAllocatorEvent(TokenAllocatorEventType type, TokenAllocatorBase allocator, @Nullable Integer numTokens,
                        @Nullable ImmutableList> sortedUnits, @Nullable ImmutableMap> unitToTokens,
                        @Nullable ImmutableMap sortedTokens, @Nullable ImmutableList tokens, Unit unit,
                        @Nullable TokenInfo tokenInfo)
    {
        this.type = type;
        this.allocator = allocator;
        this.replicas = allocator.getReplicas();
        this.numTokens = numTokens;
        this.sortedUnits = sortedUnits;
        this.unitToTokens = unitToTokens;
        this.sortedTokens = sortedTokens;
        this.tokens = tokens;
        this.unit = unit;
        this.tokenInfo = tokenInfo;
    }

    enum TokenAllocatorEventType
    {
        REPLICATION_AWARE_TOKEN_ALLOCATOR_INSTANCIATED,
        NO_REPLICATION_AWARE_TOKEN_ALLOCATOR_INSTANCIATED,
        UNIT_ADDED,
        UNIT_REMOVED,
        TOKEN_INFOS_CREATED,
        RANDOM_TOKENS_GENERATED,
        TOKENS_ALLOCATED
    }

    public TokenAllocatorEventType getType()
    {
        return type;
    }

    public HashMap toMap()
    {
        // be extra defensive against nulls and bugs
        HashMap ret = new HashMap<>();
        if (allocator != null)
        {
            if (allocator.partitioner != null) ret.put("partitioner", allocator.partitioner.getClass().getSimpleName());
            if (allocator.strategy != null) ret.put("strategy", allocator.strategy.getClass().getSimpleName());
        }
        ret.put("replicas", replicas);
        ret.put("numTokens", this.numTokens);
        ret.put("sortedUnits", String.valueOf(sortedUnits));
        ret.put("sortedTokens", String.valueOf(sortedTokens));
        ret.put("unitToTokens", String.valueOf(unitToTokens));
        ret.put("tokens", String.valueOf(tokens));
        ret.put("unit", String.valueOf(unit));
        ret.put("tokenInfo", String.valueOf(tokenInfo));
        return ret;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy