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

com.hazelcast.map.EntryProcessor Maven / Gradle / Ivy

There is a newer version: 5.5.0
Show newest version
/*
 * Copyright (c) 2008-2016, Hazelcast, Inc. All Rights Reserved.
 *
 * Licensed 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 com.hazelcast.map;

import java.io.Serializable;
import java.util.Map;

/**
 * An EntryProcessor passes you a {@link java.util.Map.Entry}. At the time you receive it
 * the entry is locked and not released until the EntryProcessor completes.
 * This obviates the need to explicitly lock as would be required with a {@link java.util.concurrent.ExecutorService}.
 * 

* Performance can be very high as the data is not moved off the Member partition. This avoids network cost and, if * the storage format is {@link com.hazelcast.config.InMemoryFormat#OBJECT}, then there is no de-serialization or serialization * cost. *

* EntryProcessors execute on the partition thread in a member. Multiple operations on the same partition are queued. *

* While executing partition migrations are not allowed. Any migrations are queued on the partition thread. *

* An EntryProcessor may not be re-entrant i.e. it may not access the same {@link Map}. Limitation: you can only access * data on the same partition. *

* Note that to modify an entry by using EntryProcessors you should explicitly call the * {@link java.util.Map.Entry#setValue} method of {@link java.util.Map.Entry} such as: *

*

 * 
 * {@literal}Override
 *     public Object process(Map.Entry entry) {
 *        Value value = entry.getValue();
 *        // process and modify value
 *        // ...
 *        entry.setValue(value);
 *        return result;
 *    }
 * 
 * 
* otherwise EntryProcessor does not guarantee that it will modify the entry. *

* EntryProcessor instances can be shared between threads. If an EntryProcessor instance contains mutable state, proper * concurrency control needs to be provided to coordinate access to mutable state. Another option is to rely on threadlocals. * * @param Type of key of a {@link java.util.Map.Entry} * @param Type of value of a {@link java.util.Map.Entry} * @see AbstractEntryProcessor */ public interface EntryProcessor extends Serializable { /** * Process the entry without worrying about concurrency. *

* Note that to modify an entry by using EntryProcessor you should explicitly call * {@link java.util.Map.Entry#setValue} method of {@link java.util.Map.Entry} such as: *

*

     * 
     * {@literal}Override
     *        public Object process(Map.Entry entry) {
     *          Value value = entry.getValue();
     *          // process and modify value
     *          // ...
     *          entry.setValue(value);
     *          return result;
     *        }
     * 
     * 
* otherwise EntryProcessor does not guarantee to modify the entry. * * @param entry entry to be processed * @return result of the process */ Object process(Map.Entry entry); /** * Get the entry processor to be applied to backup entries. * * In case of a readonly execution, null can be returned to indicate that no backups should be made. * * @return the back up processor */ EntryBackupProcessor getBackupProcessor(); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy