/** * Make a copy of a writable object using serialization to a buffer. * @param orig The object to copy * @return The copied object */ public static <T extends Writable> T clone(T orig, Configuration conf) { try { @SuppressWarnings("unchecked") // Unchecked cast from Class to Class<T> T newInst = ReflectionUtils.newInstance((Class<T>) orig.getClass(), conf); ReflectionUtils.copy(conf, orig, newInst); return newInst; } catch (IOException e) { throw new RuntimeException("Error writing/reading clone buffer", e); } }
/** * Check and set 'configuration' if necessary. * * @param theObject object for which to set configuration * @param conf Configuration */ public static void setConf(Object theObject, Configuration conf) { if (conf != null) { if (theObject instanceof Configurable) { ((Configurable) theObject).setConf(conf); } setJobConf(theObject, conf); } }
/** Construct a new {@link WritableComparable} instance. */ public WritableComparable newKey() { return ReflectionUtils.newInstance(keyClass, null); }
/** Create an object for the given class and initialize it from conf * * @param theClass class of which an object is created * @param conf Configuration * @return a new object */ @SuppressWarnings("unchecked") public static <T> T newInstance(Class<T> theClass, Configuration conf) { T result; try { Constructor<T> meth = (Constructor<T>) CONSTRUCTOR_CACHE.get(theClass); if (meth == null) { meth = theClass.getDeclaredConstructor(EMPTY_ARRAY); meth.setAccessible(true); CONSTRUCTOR_CACHE.put(theClass, meth); } result = meth.newInstance(); } catch (Exception e) { throw new RuntimeException(e); } setConf(result, conf); return result; }
/** * Make a copy of the writable object using serialization to a buffer * @param dst the object to copy from * @param src the object to copy into, which is destroyed * @throws IOException */ @SuppressWarnings("unchecked") public static <T> T copy(Configuration conf, T src, T dst) throws IOException { CopyInCopyOutBuffer buffer = cloneBuffers.get(); buffer.outBuffer.reset(); SerializationFactory factory = getFactory(conf); Class<T> cls = (Class<T>) src.getClass(); Serializer<T> serializer = factory.getSerializer(cls); serializer.open(buffer.outBuffer); serializer.serialize(src); buffer.moveData(); Deserializer<T> deserializer = factory.getDeserializer(cls); deserializer.open(buffer.inBuffer); dst = deserializer.deserialize(dst); return dst; }
getTaskName(info.getThreadId(), info.getThreadName()) + ":"); Thread.State state = info.getThreadState(); stream.println(" Blocked on " + info.getLockName()); stream.println(" Blocked by " + getTaskName(info.getLockOwnerId(), info.getLockOwnerName()));
/** Construct a new {@link WritableComparable} instance. */ public WritableComparable newKey() { return ReflectionUtils.newInstance(keyClass, null); }
/** Create an object for the given class and initialize it from conf * * @param theClass class of which an object is created * @param conf Configuration * @return a new object */ @SuppressWarnings("unchecked") public static <T> T newInstance(Class<T> theClass, Configuration conf) { T result; try { Constructor<T> meth = (Constructor<T>) CONSTRUCTOR_CACHE.get(theClass); if (meth == null) { meth = theClass.getDeclaredConstructor(EMPTY_ARRAY); meth.setAccessible(true); CONSTRUCTOR_CACHE.put(theClass, meth); } result = meth.newInstance(); } catch (Exception e) { throw new RuntimeException(e); } setConf(result, conf); return result; }
/** * Make a copy of the writable object using serialization to a buffer * @param dst the object to copy from * @param src the object to copy into, which is destroyed * @throws IOException */ @SuppressWarnings("unchecked") public static <T> T copy(Configuration conf, T src, T dst) throws IOException { CopyInCopyOutBuffer buffer = cloneBuffers.get(); buffer.outBuffer.reset(); SerializationFactory factory = getFactory(conf); Class<T> cls = (Class<T>) src.getClass(); Serializer<T> serializer = factory.getSerializer(cls); serializer.open(buffer.outBuffer); serializer.serialize(src); buffer.moveData(); Deserializer<T> deserializer = factory.getDeserializer(cls); deserializer.open(buffer.inBuffer); dst = deserializer.deserialize(dst); return dst; }
getTaskName(info.getThreadId(), info.getThreadName()) + ":"); Thread.State state = info.getThreadState(); stream.println(" Blocked on " + info.getLockName()); stream.println(" Blocked by " + getTaskName(info.getLockOwnerId(), info.getLockOwnerName()));
/** * Make a copy of a writable object using serialization to a buffer. * @param orig The object to copy * @return The copied object */ public static <T extends Writable> T clone(T orig, Configuration conf) { try { @SuppressWarnings("unchecked") // Unchecked cast from Class to Class<T> T newInst = ReflectionUtils.newInstance((Class<T>) orig.getClass(), conf); ReflectionUtils.copy(conf, orig, newInst); return newInst; } catch (IOException e) { throw new RuntimeException("Error writing/reading clone buffer", e); } }
/** * Get the value of the <code>name</code> property as a <code>List</code> * of objects implementing the interface specified by <code>xface</code>. * * An exception is thrown if any of the classes does not exist, or if it does * not implement the named interface. * * @param name the property name. * @param xface the interface implemented by the classes named by * <code>name</code>. * @return a <code>List</code> of objects implementing <code>xface</code>. */ @SuppressWarnings("unchecked") public <U> List<U> getInstances(String name, Class<U> xface) { List<U> ret = new ArrayList<>(); Class<?>[] classes = getClasses(name); for (Class<?> cl: classes) { if (!xface.isAssignableFrom(cl)) { throw new RuntimeException(cl + " does not implement " + xface); } ret.add((U) ReflectionUtils.newInstance(cl, this)); } return ret; }
/** * Check and set 'configuration' if necessary. * * @param theObject object for which to set configuration * @param conf Configuration */ public static void setConf(Object theObject, Configuration conf) { if (conf != null) { if (theObject instanceof Configurable) { ((Configurable) theObject).setConf(conf); } setJobConf(theObject, conf); } }
/** * Get the value of the <code>name</code> property as a <code>List</code> * of objects implementing the interface specified by <code>xface</code>. * * An exception is thrown if any of the classes does not exist, or if it does * not implement the named interface. * * @param name the property name. * @param xface the interface implemented by the classes named by * <code>name</code>. * @return a <code>List</code> of objects implementing <code>xface</code>. */ @SuppressWarnings("unchecked") public <U> List<U> getInstances(String name, Class<U> xface) { List<U> ret = new ArrayList<U>(); Class<?>[] classes = getClasses(name); for (Class<?> cl: classes) { if (!xface.isAssignableFrom(cl)) { throw new RuntimeException(cl + " does not implement " + xface); } ret.add((U) ReflectionUtils.newInstance(cl, this)); } return ret; }
@SuppressWarnings("unchecked") private void add(Configuration conf, String serializationName) { try { Class<? extends Serialization> serializationClass = (Class<? extends Serialization>) conf.getClassByName(serializationName); serializations.add( ReflectionUtils.newInstance(serializationClass, getConf())); } catch (ClassNotFoundException e) { LOG.warn("Serialization class not found: " + StringUtils.stringifyException(e)); } }
@SuppressWarnings("unchecked") private void add(Configuration conf, String serializationName) { try { Class<? extends Serialization> serializionClass = (Class<? extends Serialization>) conf.getClassByName(serializationName); serializations.add( ReflectionUtils.newInstance(serializionClass, getConf())); } catch (ClassNotFoundException e) { LOG.warn("Serilization class not found: " + StringUtils.stringifyException(e)); } }