|
| 1 | +/* |
| 2 | +Copyright 2012 Twitter, Inc. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | +http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package com.twitter.chill.storm; |
| 18 | + |
| 19 | +import org.apache.storm.serialization.IKryoFactory; |
| 20 | +import com.esotericsoftware.kryo.kryo5.Kryo; |
| 21 | +import java.util.Map; |
| 22 | + |
| 23 | +import com.twitter.chill.KryoInstantiator; |
| 24 | +import com.twitter.chill.config.JavaMapConfig; |
| 25 | +import com.twitter.chill.config.ConfiguredInstantiator; |
| 26 | +import com.twitter.chill.config.ConfigurationException; |
| 27 | + |
| 28 | +/** BlizzardKryoFactory. get it? chilly storm. |
| 29 | + * This is a thin wrapper for using the ConfiguredInstantiator. It |
| 30 | + * creates the entire kryo object in the getKryo method and then |
| 31 | + * doesn't do anything else. |
| 32 | + * |
| 33 | + * To set this up, you probably want to use ConfiguredInstantitator with |
| 34 | + * the JavaMapConfig. |
| 35 | + */ |
| 36 | +public class BlizzardKryoFactory implements IKryoFactory { |
| 37 | + public Kryo getKryo(Map conf) { |
| 38 | + KryoInstantiator kryoInst; |
| 39 | + try { |
| 40 | + kryoInst = new ConfiguredInstantiator(new JavaMapConfig(conf)); |
| 41 | + return kryoInst.newKryo(); |
| 42 | + } |
| 43 | + catch(ConfigurationException cx) { throw new RuntimeException(cx); } |
| 44 | + } |
| 45 | + public void preRegister(Kryo k, Map conf) { } |
| 46 | + public void postRegister(Kryo k, Map conf) { } |
| 47 | + public void postDecorate(Kryo k, Map conf) { } |
| 48 | +} |
0 commit comments