com.hazelcast.mapreduce.LifecycleMapperAdapter Maven / Gradle / Ivy
/*
* Copyright (c) 2008-2015, 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.mapreduce;
import com.hazelcast.spi.annotation.Beta;
/**
*
* The abstract LifecycleMapperAdapter superclass is used to ease building mappers for the {@link Job}.
* Most mappers will only implement the {@link #map(Object, Object, Context)} method to collect and
* emit needed key-value pairs.
* For more complex algorithms there is the possibility to override the {@link #initialize(Context)} and
* {@link #finalized(Context)} methods as well.
*
*
* A simple mapper could look like the following example:
*
*
* public static class MyMapper extends LifecycleMapperAdapter<Integer, Integer, String, Integer>
* {
* public void map( Integer key, Integer value, Context<String, Integer> collector )
* {
* collector.emit( String.valueOf( key ), value );
* }
* }
*
*
*
* If you want to know more about the implementation of MapReduce algorithms read the {@see Google Whitepaper on MapReduce}.
*
*
* @param type of key used in the {@link KeyValueSource}
* @param type of value used in the {@link KeyValueSource}
* @param key type for mapped results
* @param value type for mapped results
* @since 3.2
*/
@Beta
public abstract class LifecycleMapperAdapter
implements LifecycleMapper {
/**
* {@inheritDoc}
*/
public void initialize(Context context) {
}
/**
* {@inheritDoc}
*/
public abstract void map(KeyIn key, ValueIn value, Context context);
/**
* {@inheritDoc}
*/
public void finalized(Context context) {
}
}