In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
Hadoop AbstractMapWritable and its implementation class is how, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
As an abstract Map container Writable type, AbstractMapWritable mainly provides a set of index table structure for its implementation classes MapWritable and SortedMapWritable, as follows:
Map classToIdMap = new ConcurrentHashMap () / / id to Class mapping table Map idToClassMap = new ConcurrentHashMap (), / / class to Id mapping table
The index table needs to add a new class object and Id mapping, which is bound to require a new Id variable, and the class object is used as a method parameter, as follows
Private volatile byte newClasses = 0
With the above data structure, we need to add some data manipulation methods. Since the basic data structure of AbstractMapWritable is about index tables, indexes will naturally be added.
Private synchronized void addToMap (Class clazz, byte id) {/ / mainly implements the function of whether the operation of the index id exists through two index tables, and throws an exception if the index Id exists but is not a formal parameter id Otherwise, add index information} protected synchronized void addToMap (Class clazz) {/ / there is no index id, and the current index variable newClasses Byte.MAX_VALUE) {throw new IndexOutOfBoundsException ("adding an additional class would" + "exceed the maximum number allowed") } byte id = + + newClasses; addToMap (clazz, id);}
AbstractMapWritable provides a protected constructor
Protected AbstractMapWritable () {this.conf = new AtomicReference (); / / add the index information of the underlying serialization type. The index table can represent only-127-128 types of addToMap (ArrayWritable.class, Byte.valueOf (Integer.valueOf (- 127d). ByteValue ()); addToMap (BooleanWritable.class, Byte.valueOf (Integer.valueOf (- 12626). ByteValue () AddToMap (BytesWritable.class, Byte.valueOf (Integer.valueOf (- 125B). ByteValue ()); addToMap (FloatWritable.class, Byte.valueOf (Integer.valueOf (- 12412). ByteValue ()); addToMap (IntWritable.class, Byte.valueOf (Integer.valueOf (- 123B). ByteValue ()); addToMap (LongWritable.class, Byte.valueOf (Integer.valueOf (- 122c). ByteValue () AddToMap (MapWritable.class, Byte.valueOf (Integer.valueOf (- 121l). ByteValue ()); addToMap (MD5Hash.class, Byte.valueOf (Integer.valueOf (- 120.byteValue (); addToMap (NullWritable.class, Byte.valueOf (Integer.valueOf (- 119.1). ByteValue ()); addToMap (ObjectWritable.class, Byte.valueOf (Integer.valueOf (- 118.1). ByteValue () AddToMap (SortedMapWritable.class, Byte.valueOf (Integer.valueOf-117.byteValue ()); addToMap (Text.class, Byte.valueOf (Integer.valueOf (- 116.1). ByteValue ()); addToMap (TwoDArrayWritable.class, Byte.valueOf (Integer.valueOf (- 115.1). ByteValue () / / UTF8 is deprecated so we don't support it addToMap (VIntWritable.class, Byte.valueOf (Integer.valueOf) .byteValue ()); addToMap (VLongWritable.class, Byte.valueOf (Integer.valueOf (- 113.1). ByteValue ());}
Followed by serialization and deserialization methods
Serialization: writing index information to the stream
/ / the serialization method first writes the current index variable newClasses, and then writes the combined public void write (DataOutput out) throws IOException {/ / First write out the size of the class table and any classes that are / / "unknown" classes / / of the index Id+ class name from the index ID out.writeByte range [1ref newClasss] to index ID out.writeByte (newClasses). / * do not understand why only part of the index information of [1~newClasses] is written instead of [- 127~newClasses index information]. * * guess that it may be related to the subclass overriding its protected constructor, because the default initial newClasses is 0 * / for (byte I = 1; I).
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.