📄 ldapjobhoststatefactory.java
字号:
/* * LdapJobHostStateFactory.java * * Created on April 16, 2005, 2:12 PM */package jwsgrid.resourcemanager.priv;import javax.naming.*;import javax.naming.directory.*;import javax.naming.spi.DirStateFactory;import java.util.Hashtable;/** * * @author sean */public class LdapJobHostStateFactory implements DirStateFactory { /** Creates a new instance of LdapJobHostStateFactory */ public LdapJobHostStateFactory() { } // DirStateFactory version public DirStateFactory.Result getStateToBind( Object obj, Name name, Context ctx, Hashtable env, Attributes inAttrs ) throws NamingException { // Only interested in Person objects if ( obj instanceof LdapJobHost ) { Attributes outAttrs; if ( inAttrs == null ) { outAttrs = new BasicAttributes( true ); } else { outAttrs = (Attributes) inAttrs.clone(); } // Set up object class if ( outAttrs.get( "objectclass" ) == null ) { BasicAttribute oc = new BasicAttribute( "objectclass", Ldap.OBJ_JOBHOST ); oc.add( Ldap.ATTR_TOP ); outAttrs.put( oc ); } LdapJobHost jobHost = (LdapJobHost) obj; // mandatory attributes if ( jobHost.clusterId != null ) { outAttrs.put( Ldap.ATTR_JHCLUSTERID, jobHost.clusterId ); } else { throw new SchemaViolationException( "cluster id missing" ); } if ( jobHost.osName != null ) { outAttrs.put( Ldap.ATTR_JHOS_NAME, jobHost.osName ); } else { throw new SchemaViolationException( "os name missing" ); } if ( jobHost.osVersion != null ) { outAttrs.put( Ldap.ATTR_JHOS_VERSION, jobHost.osVersion ); } else { throw new SchemaViolationException( "os version missing" ); } if ( jobHost.osArch != null ) { outAttrs.put( Ldap.ATTR_JHOS_ARCH, jobHost.osArch ); } else { throw new SchemaViolationException( "os arch missing" ); } if ( jobHost.cpuVendor != null ) { outAttrs.put( Ldap.ATTR_JHCPU_VENDOR, jobHost.cpuVendor ); } else { throw new SchemaViolationException( "cpu vendor missing" ); } if ( jobHost.cpuModel != null ) { outAttrs.put( Ldap.ATTR_JHCPU_MODEL, jobHost.cpuModel ); } else { throw new SchemaViolationException( "cpu model missing" ); } if ( jobHost.cpuCount != null ) { outAttrs.put( Ldap.ATTR_JHCPU_COUNT, jobHost.cpuCount.toString() ); } else { throw new SchemaViolationException( "cpu count missing" ); } if ( jobHost.cpuSpeed != null ) { outAttrs.put( Ldap.ATTR_JHCPU_SPEED, jobHost.cpuSpeed.toString() ); } else { throw new SchemaViolationException( "cpu speed missing" ); } if ( jobHost.cpuUserTime != null ) { outAttrs.put( Ldap.ATTR_JHCPU_USERTIME, jobHost.cpuUserTime.toString() ); } else { throw new SchemaViolationException( "cpu user time missing" ); } if ( jobHost.cpuIdleTime != null ) { outAttrs.put( Ldap.ATTR_JHCPU_IDLETIME, jobHost.cpuIdleTime.toString() ); } else { throw new SchemaViolationException( "cpu idle time missing" ); } if ( jobHost.cpuSysTime != null ) { outAttrs.put( Ldap.ATTR_JHCPU_SYSTIME, jobHost.cpuSysTime.toString() ); } else { throw new SchemaViolationException( "cpu sys time missing" ); } if ( jobHost.cpuLoad != null ) { outAttrs.put( Ldap.ATTR_JHCPU_LOAD, jobHost.cpuLoad.toString() ); } else { throw new SchemaViolationException( "cpu load missing" ); } if ( jobHost.memTotal != null ) { outAttrs.put( Ldap.ATTR_JHMEM_TOTAL, jobHost.memTotal.toString() ); } else { throw new SchemaViolationException( "total mem missing" ); } if ( jobHost.memFree != null ) { outAttrs.put( Ldap.ATTR_JHMEM_FREE, jobHost.memFree.toString() ); } else { throw new SchemaViolationException( "free memory missing" ); } if ( jobHost.diskSpaceTot != null ) { outAttrs.put( Ldap.ATTR_JHDISK_TOTAL, jobHost.diskSpaceTot.toString() ); } else { throw new SchemaViolationException( "total disk space missing" ); } if ( jobHost.diskSpaceFree != null ) { outAttrs.put( Ldap.ATTR_JHDISK_FREE, jobHost.diskSpaceFree.toString() ); } else { throw new SchemaViolationException( "free disk space missing" ); } if ( jobHost.jobTypeList != null ) { BasicAttribute attr = new BasicAttribute( Ldap.ATTR_JHJOBTYPES ); for ( int i = 0; i < jobHost.jobTypeList.size(); i++ ) { attr.add( jobHost.jobTypeList.get( i ) ); } outAttrs.put( attr ); } else { throw new SchemaViolationException( "job type(s) missing" ); } return new DirStateFactory.Result( null, outAttrs ); } return null; } // StateFactory version public Object getStateToBind( Object obj, Name name, Context ctx, Hashtable env) throws NamingException { // non-Attributes version not relevant here return null; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -