petrov-mg commented on code in PR #13243: URL: https://github.com/apache/ignite/pull/13243#discussion_r3455766492
########## modules/core/src/main/java/org/apache/ignite/internal/thread/context/DistributedOperationContextManager.java: ########## @@ -0,0 +1,128 @@ +/* + * 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.ignite.internal.thread.context; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentSkipListMap; +import org.apache.ignite.IgniteException; +import org.apache.ignite.internal.DistributedOperationContextMessage; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.plugin.extensions.communication.Message; +import org.jetbrains.annotations.Nullable; + +/** + * A manager of {@link OperationContextAttribute} which are required to be propagated through a cluster. + * Has own attributes ids compared to a local node's {@link OperationContext}. + * + * @see OperationContext + * @see DistributedOperationContextMessage + */ +public class DistributedOperationContextManager { + /** */ + private static final DistributedOperationContextManager INSTANCE = new DistributedOperationContextManager(); + + /** Maximal number of supported distributed attributes. */ + static final byte MAX_DISTRIBUTED_ATTR_CNT = Byte.SIZE; + + /** Registered distributed attributes by their cluster-wide id. */ + private final Map<Byte, OperationContextAttribute<? extends Message>> attrs = new ConcurrentSkipListMap<>(); + + /** */ + public static DistributedOperationContextManager instance() { + return INSTANCE; + } + + /** + * Creates and registers a distributable {@link OperationContextAttribute}. + * + * @param id Cluster-wide id of a distributed operation context attribute. + * @param initVal The attribute's unitial value. + */ + public <T extends Message> OperationContextAttribute<T> createDistributedAttribute(byte id, @Nullable T initVal) { + assert id >= 0 && id < MAX_DISTRIBUTED_ATTR_CNT : "Invalid distributed attributed id [id=" + id + ']'; + + return (OperationContextAttribute<T>)attrs.compute(id, (id0, attr0) -> { + if (attr0 != null) + throw new IgniteException("Duplicated distributed attribute id [id=" + id + ']'); + + return OperationContextAttribute.newInstance(initVal); + }); + } + + /** + * Requests current {@link OperationContext} for its effective attributes and collects ones which are also registered Review Comment: ``` /** * Collects the values of all distributed {@link OperationContextAttribute}s registered by this manager * in a format suitable for transmission between cluster nodes. * * @see OperationContext#get(OperationContextAttribute) */ ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
