protected boolean matchesType(H2O.KeyInfo ki) { // No type filtering if( _typeid == 0 && _cname == null ) return true; // One-shot monotonic racey update from 0 to the known fixed typeid. // Since all writers write the same typeid, there is no race. if( _typeid == 0 ) _typeid = TypeMap.onIce(_cname); if( ki._type == _typeid ) return true; // Class Model is abstract, and TypeMap clazz() does not handle that well. // Also, want to allow both OldModel & Model. // Hack: check for water.Model and name the class directly. Class kclz = TypeMap.clazz(ki._type); if( TypeMap.className(_typeid).equals("water.Model") ) return Model.class.isAssignableFrom(kclz); return TypeMap.clazz(_typeid).isAssignableFrom(kclz); }
static public Class clazz(int id) { if( id >= CLAZZES.length || CLAZZES[id] == null ) loadId(id); if( GOLD[id] == null ) newInstance(id); return GOLD[id].getClass(); } }
public boolean isVec() { return _type != TypeMap.PRIM_B && (TypeMap.newInstance(_type) instanceof Vec); } public boolean isByteVec() { return _type != TypeMap.PRIM_B && (TypeMap.newInstance(_type) instanceof ByteVec); }
static public Iced newInstance(int id) { if( id >= CLAZZES.length || CLAZZES[id] == null ) loadId(id); Iced f = (Iced) GOLD[id]; if( f == null ) { try { GOLD[id] = f = (Iced) Class.forName(CLAZZES[id]).newInstance(); } catch( Exception e ) { Log.err("Failed newinstance for class "+className(id)); throw Log.errRTExcept(e); } } return f.newInstance(); }
public <T extends Iced> Map<String, T> fetchAll(Class<T> c, boolean exact, int offset, int limit) { TreeMap<String, T> res = new TreeMap<String, T>(); final int typeId = TypeMap.onIce(c.getName()); for (KeyInfo kinfo : _keyInfos) { if (kinfo._type == typeId || (!exact && c.isAssignableFrom(TypeMap.clazz(kinfo._type)))) { if (offset > 0) { --offset; continue; } Value v = DKV.get(kinfo._key); if (v != null) { T t = v.get(); res.put(kinfo._key.toString(), t); if (res.size() == limit) break; } } } return res; } public static KeySnapshot localSnapshot(){return localSnapshot(false);}
public boolean isFrame(){ return _type == TypeMap.onIce(Frame.class.getName()); } public boolean isLockable(){
public String className() { return TypeMap.className(_type); }
static public void loadId(int id) { assert H2O.CLOUD.leader() != H2O.SELF; // Leaders always have the latest mapping already install( FetchClazz.fetchClazz(id), id ); }
static public String className(int id) { if( id >= CLAZZES.length || CLAZZES[id] == null ) loadId(id); assert CLAZZES[id] != null : "No class matching id "+id; return CLAZZES[id]; } static public Class clazz(int id) {
public <T extends Freezable> T get(Class<T> t) { short id = (short)get2(); if( id == TypeMap.NULL ) return null; assert id > 0 : "Bad type id "+id; return TypeMap.newFreezable(id).read(this); } public <T extends Iced> T get() {
public boolean isLockable(){ return TypeMap.newInstance(_type) instanceof Lockable; } }
@Override public int frozenType() { return _frozen$type == 0 ? (_frozen$type=water.TypeMap.onIce(IcedHashMap.class.getName())) : _frozen$type; } @Override public AutoBuffer writeJSONFields(AutoBuffer bb) { return bb; }
@Override public void compute2() { _clazz = TypeMap.className(_id); tryComplete(); } @Override public byte priority() { return H2O.FETCH_ACK_PRIORITY; }
static public int onIce(String className) { Integer I = MAP.get(className); if( I != null ) return I; // Need to install a new cloud-wide type ID for className assert H2O.CLOUD.size() > 0 : "No cloud when getting type id for "+className; int id = -1; if( H2O.CLOUD.leader() != H2O.SELF ) // Not leader? id = FetchId.fetchId(className); return install(className,id); }
static public Freezable newFreezable(int id) { assert id >= 0 : "Bad type id "+id; if( id >= CLAZZES.length || CLAZZES[id] == null ) loadId(id); Freezable f = GOLD[id]; if( f == null ) { try { GOLD[id] = f = (Freezable) Class.forName(CLAZZES[id]).newInstance(); } catch( Exception e ) { throw Log.errRTExcept(e); } } return f.newInstance(); }
public <T extends Freezable> T getFreezable() { touch(); Freezable pojo = _pojo; // Read once! if( pojo != null ) return (T)pojo; pojo = TypeMap.newFreezable(_type); pojo.read(new AutoBuffer(memOrLoad())); if( pojo instanceof Iced ) ((Iced)pojo).init(_key); return (T)(_pojo = pojo); }
public boolean isLockable(){ return _type != TypeMap.PRIM_B && (TypeMap.newInstance(_type) instanceof Lockable); } public boolean isFrame() { return _type == TypeMap.FRAME; }
@Override public int frozenType() { return _frozen$type == 0 ? (_frozen$type=water.TypeMap.onIce(IcedArrayList.class.getName())) : _frozen$type; } @Override public AutoBuffer writeJSONFields(AutoBuffer bb) {
@Override public String print16( AutoBuffer ab ) { int flag = ab.getFlag(); String clazz = (flag == CLIENT_UDP_SEND) ? TypeMap.className(ab.get2()) : ""; return "task# "+ab.getTask()+" "+ clazz+" "+COOKIES[flag-SERVER_UDP_SEND]; } }
public boolean isByteVec() { return _type != TypeMap.PRIM_B && (TypeMap.newInstance(_type) instanceof ByteVec); } public boolean isRawData() {