⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ldap.java

📁 这是一个基于计算网格的web service。它用java编写。一旦安装完成
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                if ( context != null ) {                    context.close();                    context = null;                }                            } catch ( Exception e ) {}        }                 return success;    }         public static List<JobHostResult> searchJobHosts(             String filter,             int numMatches,            Map<String,String> blockedWsAddrTable )    throws Exception     {        DirContext context = null;          Vector<JobHostResult> matches = new Vector();                if ( numMatches < 0 )         {            return matches;        }                if ( filter == null | filter.length() == 0 )         {            filter = "(" + ATTR_CN + "=*)";         }        try         {            Hashtable env = new Hashtable();            env.put( Context.INITIAL_CONTEXT_FACTORY, LDAP_CONTEXTFACTORY );            env.put( Context.PROVIDER_URL, getProviderUrl() );            env.put( Context.OBJECT_FACTORIES, JOBHOST_OBJFACTORY );            env.put( Context.STATE_FACTORIES, JOBHOST_STATEFACTORY );                                // get the context            context = new InitialDirContext( env );                        // create search controls            String[] attrIDs = new String[]             {                     ATTR_CN,                     ATTR_JHCLUSTERID,                    ATTR_JHRESERVED             };            SearchControls ctls = new SearchControls();            ctls.setReturningAttributes( attrIDs );            //ctls.setCountLimit( numMatches );                         NamingEnumeration nameEnum = context.search(                     getResMgrDir(), filter, ctls );                            try             {                while( nameEnum.hasMore() )                 {                    SearchResult result = (SearchResult) nameEnum.next();                                        Attributes attribs = result.getAttributes();                    Attribute attr = attribs.get( ATTR_JHRESERVED );                    if ( attr != null )                     {                        // skip reserved JobHosts                        continue;                    }                                        JobHostResult jobHostResult = new JobHostResult();                    if ( (attr = attribs.get( ATTR_CN )) != null )                     {                        jobHostResult.setWsAddr( (String) attr.get() );                    }                                        else                    {                        continue;                    }                                        if ( blockedWsAddrTable != null )                    {                        if ( blockedWsAddrTable.get( (String) attr.get() ) != null )                        {                            continue;                        }                    }                                        if ( (attr = attribs.get( ATTR_JHCLUSTERID )) != null )                     {                        jobHostResult.setClusterId( (String) attr.get() );                    }                                                    else                    {                        continue;                    }                                        matches.addElement( jobHostResult );                                        if ( matches.size() >= numMatches )                    {                        break;                    }                }                            } catch ( SizeLimitExceededException se ) {}                    } catch ( Exception ex ) {            throw ex;                    } finally {            try             {                if ( context != null )                 {                    context.close();                    context = null;                }                            } catch ( Exception e ) {}        }                 return matches;    }        public static List<LdapJobHost> getJobHosts() throws Exception    {        DirContext context = null;          Vector<LdapJobHost> list = new Vector();                try         {            Hashtable env = new Hashtable();            env.put( Context.INITIAL_CONTEXT_FACTORY, LDAP_CONTEXTFACTORY );            env.put( Context.PROVIDER_URL, getProviderUrl() );            env.put( Context.OBJECT_FACTORIES, JOBHOST_OBJFACTORY );            env.put( Context.STATE_FACTORIES, JOBHOST_STATEFACTORY );                                // get the context            context = new InitialDirContext( env );                        // create a filter to return all job hosts            String[] attrIDs = new String[]             {                 ATTR_CN,                 ATTR_JHRESERVED,                ATTR_JHCLUSTERID,                ATTR_JHOS_NAME,                ATTR_JHOS_VERSION,                ATTR_JHOS_ARCH,                ATTR_JHCPU_VENDOR,                ATTR_JHCPU_MODEL,                ATTR_JHCPU_SPEED,                ATTR_JHCPU_COUNT,                ATTR_JHCPU_USERTIME,                ATTR_JHCPU_IDLETIME,                ATTR_JHCPU_SYSTIME,                ATTR_JHCPU_LOAD,                ATTR_JHMEM_TOTAL,                ATTR_JHMEM_FREE,                ATTR_JHDISK_TOTAL,                ATTR_JHDISK_FREE,                ATTR_JHJOBTYPES            };                        SearchControls ctls = new SearchControls();            ctls.setReturningAttributes( attrIDs );                        String filter = "(cn=*)";                         NamingEnumeration nameEnum = context.search(                     getResMgrDir(),                     filter,                     ctls );                            try             {                while( nameEnum.hasMore() )                 {                    SearchResult result = (SearchResult) nameEnum.next();                    Attributes attribs = result.getAttributes();                    Attribute attr = null;                    LdapJobHost jobHost = new LdapJobHost();                    if ( (attr = attribs.get( ATTR_CN )) == null )                     {                        continue;                    }                                        jobHost.wsaddr = (String) attr.get();                                        if ( (attr = attribs.get( ATTR_JHCLUSTERID )) == null )                     {                        continue;                    }                                        jobHost.clusterId = (String) attr.get();                    if ( (attr = attribs.get( ATTR_JHOS_NAME )) == null )                     {                        continue;                    }                                        jobHost.osName = (String) attr.get();                                        if ( (attr = attribs.get( ATTR_JHOS_VERSION )) == null )                     {                        continue;                    }                                        jobHost.osVersion = (String) attr.get();                                        if ( (attr = attribs.get( ATTR_JHOS_ARCH )) == null )                     {                        continue;                    }                                        jobHost.osArch = (String) attr.get();                                        if ( (attr = attribs.get( ATTR_JHCPU_VENDOR )) == null )                     {                        continue;                    }                                        jobHost.cpuVendor = (String) attr.get();                                        if ( (attr = attribs.get( ATTR_JHCPU_MODEL )) == null )                     {                        continue;                    }                                        jobHost.cpuModel = (String) attr.get();                                        if ( (attr = attribs.get( ATTR_JHCPU_SPEED )) == null )                     {                        continue;                    }                                        jobHost.cpuSpeed = new Integer( (String) attr.get() );                                        if ( (attr = attribs.get( ATTR_JHCPU_COUNT )) == null )                     {                        continue;                    }                                        jobHost.cpuCount = new Integer( (String) attr.get() );                                        if ( (attr = attribs.get( ATTR_JHCPU_USERTIME )) == null )                     {                        continue;                    }                                        jobHost.cpuUserTime = new Integer( (String) attr.get() );                    if ( (attr = attribs.get( ATTR_JHCPU_IDLETIME )) == null )                     {                        continue;                    }                                        jobHost.cpuIdleTime = new Integer( (String) attr.get() );                                            if ( (attr = attribs.get( ATTR_JHCPU_SYSTIME )) == null )                     {                        continue;                    }                                        jobHost.cpuSysTime = new Integer( (String) attr.get() );                                         if ( (attr = attribs.get( ATTR_JHCPU_LOAD )) == null )                     {                        continue;                    }                                        jobHost.cpuLoad = new Integer( (String) attr.get() );                                                             if ( (attr = attribs.get( ATTR_JHMEM_TOTAL )) == null )                     {                        continue;                    }                                        jobHost.memTotal = new Integer( (String) attr.get() );                                         if ( (attr = attribs.get( ATTR_JHMEM_FREE )) == null )                     {                        continue;                    }                                        jobHost.memFree = new Integer( (String) attr.get() );                                         if ( (attr = attribs.get( ATTR_JHDISK_TOTAL )) == null )                     {                        continue;                    }                                        jobHost.diskSpaceTot = new Integer( (String) attr.get() );                                         if ( (attr = attribs.get( ATTR_JHDISK_FREE )) == null )                     {                        continue;                    }                                        jobHost.diskSpaceFree = new Integer( (String) attr.get() );                                         if ( (attr = attribs.get( ATTR_JHJOBTYPES )) == null )                     {                        continue;                    }                                        for ( int i = 0; i < attr.size(); i++ )                    {                        jobHost.jobTypeList.addElement( (String) attr.get( i ) );                    }                                                           list.addElement( jobHost );                }                            } catch ( SizeLimitExceededException se ) {}                    } catch ( Exception ex ) {            throw ex;                    } finally {            try             {                if ( context != null )                 {                    context.close();                    context = null;                }                            } catch ( Exception e ) {}        }                         return list;    }        ////////////////////////////////////////////////////////////////////////////    // private methods    //      private static String doCharEscape( String src )     {        String result = "";                for ( int i = 0; i < src.length(); i++ )         {            if ( src.charAt( i ) == '/' )             {                result += "\\";            }            result += src.charAt( i );        }                return result;    }  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -