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

📄 queueheader.java

📁 一个java RMI 调用的FrameWork, 由IBM提供
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* 
 * Copyright (C) 2001 Cooperative Software Systems, Inc.  <info@coopsoft.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You received a copy of the GNU General Public License
 * along with this software. For more information on GNU, see
 * http://www.gnu.org or write to: the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

public final class QueueHeader {
    
    // instance fields 
    private String  que_name;   // name of this queue                  
    private String  pap_name;   // name of class to invoke
    private FrameWorkBase  T;   // addr of base storage
    private WaitLists waitlist;  // addr of wait lists   
    private int que_number;     // seq number from zero
    private int nbr_waitlists;  // number of wait lists
    private int nbr_wl_entries; // number of entries in a waitlist 
    private int wait_time;      // time to wait when no work
    private int nbr_threads;    // total threads for this queue 
    private int que_type;       // type of queue 0=normal, 1=agent 
    
    private QueueDetail[] details;   // detail array of thread info
    
    // public data for use by the Queue Thread program and startup
    public DemoCall to_call; // class to call   
    
/**
 * On an overall status request check for non-disabled threads
 * 
 */
 
public boolean checkThreads () {
         
    // loop thru the details  
    for  (int i = 0; i < nbr_threads; i++) {
           
          // When a thread is not disabled
          if  (details[i].getStatus() != QueueDetail.DISABLED) {
              
              // found a live one
              return true;

          } // endif
    } // end-for  

    // no threads are active    
    return false;
    
} // end-method                                                     

/**
 * 
 */

public String[] fetchThreads () {
    
    int i, proc, nbr = 0;
    String[] th_data = new String[nbr_threads];    
    
    // loop thru the details  
    for  (i = 0; i < nbr_threads; i++, nbr++) {
            
          // get the number processed
          proc = details[i].getTotProc();
                      
          // get the status of the thread 
          switch (details[i].getStatus()) {
            
              case QueueDetail.INITIALIZED :

                    // say in english, done
                    th_data[i] = + nbr
                                 + ", ("
                                 + proc
                                 + ") - Never used";
                    // get out
                    break;                                              
                        
              case QueueDetail.DETACHED :

                    // say in english, done
                    th_data[i] = nbr
                                + ", ("
                                + proc 
                                + ") - Inactive";
  
                    // get out
                    break;                                               
                  
              case QueueDetail.WAITING :
                      
                        // say in english, done
                        th_data[i] = nbr 
                                        + ", ("
                                        + proc
                                        + ") - Waiting for work";
                        // get out
                        break;                                            
                  
              case QueueDetail.PROCESSING :  
                      
                        // say in english, done
                        th_data[i] = nbr 
                                        + ", ("
                                        + proc
                                        + ") - Thread processing";
                        // get out
                        break;                                             
                  
              case QueueDetail.INLINK_APPL : 
                      
                        // say in english, done
                        th_data[i] = nbr 
                                        + ", ("
                                        + proc
                                        + ") - In application Class";
                        // get out
                        break;                                              
                  
              case QueueDetail.INLINK_SCHD : 
                      
                        // say in english, done
                        th_data[i] = nbr 
                                        + ", ("
                                        + proc
                                        + ") - Scheduling Output Agent";
                        // get out
                        break;                                               
                  
              case QueueDetail.POSTED :      
                      
                        // say in english, done
                        th_data[i] = nbr 
                                        + ", ("
                                        + proc
                                        + ") - Notified, awaiting execution";
                        // get out
                        break;                                                
                  
              case QueueDetail.STARTED :     
                      
                        // say in english, done
                        th_data[i] = nbr 
                                        + ", ("
                                        + proc
                                        + ") - Reactivated, awaiting execution";
                        // get out
                        break;    
              
              case QueueDetail.DISABLED :

                      // SAY 
                      th_data[i] = nbr 
                                 + ", ("
                                 + proc
                                + ") - Disabled";
  
                      // get out
                       break;              
                                                
            } // end-switch
    } // end-for 
            
    return th_data;
    
} // end-method
/**
 *
 * get all the wait list entries that are busy.
 *   this means looping thru all the wait lists and accum those busy
 *
 * 
 * @return int
 */

public int getAllWlBusy () {
    
    // addr of first waitlist
    WaitLists WL = waitlist;
    
    int i, count = 0;
    
    // loop thru waitlists
    for  (i = 0; i < nbr_waitlists; i++) {
      
           // accum the busy in the waitlist
          count += WL.getWlBusy();
          
          // get the next addr in the linked list
          WL = WL.getNext();

    } // endfor 
    
    return count;
    
} // end-method
/**
 *
 * Get the first available detail that can accept a new thread
 *
 * 
 * @return int
 */
 
public int getAvailable ( ) {    
    
    int i, status;
    
    // look at all the threads
    for  (i = 0; i < nbr_threads; i++) {

          // thread status
          status = details[i].getStatus();  

          // When
          if  ((status == QueueDetail.INITIALIZED) ||
               (status == QueueDetail.DETACHED)) {

              // return position  
                 return i;

          } // endif          
    } // end-for

    // none available   
    return -1;
  
} // end-method

/**
 * 
 * 
 * @return int
 */

public int getBusy () {
    
    int i, count = 0;
    int status;
    
    // count the threads that are busy with a request
    for  (i = 0; i < nbr_threads; i++) {

          // status
          status = details[i].getStatus();  

          // When:
          if  ((status == QueueDetail.PROCESSING)     ||
               (status == QueueDetail.INLINK_APPL)  ||
               (status == QueueDetail.INLINK_SCHD)  ||
               (status == QueueDetail.POSTED)         ||
               (status == QueueDetail.STARTED)) {

              // one found
              count++;

           } // endif         
    } // end-for
    
    return count;
    
} // end-method

/**
 *
 * Get the first wait list entry that is busy.  This means starting
 *   from the first waitlist, (priority 1), and working thru all the
 *   waitlists until a busy is found, or, there are no more waitlists.  
 *
 * @return int
 */

public int getFirstBusy () {
    

    // addr of first waitlist
    WaitLists WL = waitlist; 

    int k = 0;
    
    // until found
    while  (true) {
  
        // get the first busy in this waitlist
        k = WL.fetchFirstBusy();
        
        // When found one
        if  (k != 0) {

            // get out
            break;

        } // endif
        
        // bump to next waitlist
        WL = WL.getNext();

        //  When no more lists
        if  (WL == null)  {

            // get out 
            break;

       } // endif            
    } // end-while               
                  
    return k;
  
  }// end-method              

/**
 *
 *
 */
        
public String getName() {
   
   return que_name;        
                      
} // end-method     
/**
 * 
 * @return int
 */
  
public int getNbrInWl ( ) {
  
    return nbr_wl_entries;
    
} // end-method
/**
 * 
 * @return int
 */
 
public int getNbrThreads ( ) {
  
    return nbr_threads;
    
} // end-method
/**
 * 
 * @return int
 */

public int getNbrWl ( ) {
  
    return nbr_waitlists;
    
} // end-method                

/**
 * 
 * @return java.lang.String
 */

public String getPaClass ( ) {
  
    return pap_name;
    
} // end-method
/**
 * 
 * @return int
 */
 
public int getQueNumber ( ) {
  
    return que_number;
    
} // end-method
/**
 * 
 * @return int
 */
  
public int getQueType ( ) {
  
    return que_type;
    
} // end-method
/**
 * 
 * @return int
 */

public int getThAvail ( ) {
    
    // the status of a detail entry must be other than disablef 
    for  (int i = 0; i < nbr_threads; i++) {

          // When less than cancelled
          if  (details[i].getStatus() < QueueDetail.DISABLED) {

              // found one
              return 0;

          } // endif          
    } // end-for
   
    // none available
    return 1;
    
} // end-method

/**
 *
 * 
 * 
 * @return int
 */
  
public int getWaitTime ( ) {
    
    
    return wait_time;
  
} // end-method
/**
 * 
 * @return int
 */

public int getWlAvail ( ) {
    
    
    // addr of first waitlist
    WaitLists WL = waitlist;
    
    int i;
    
    // loop thru waitlists
    for  (i = 0; i < nbr_waitlists; i++) {
      
          // look for an available entry in the waitlist
          if  (WL.getAvail() == 0) {

              // found  
              return 0;

          } // endif
           
          // get the next addr in the linked list
          WL = WL.getNext();

    } // endfor 

    // none available   
    return 1;
    
} // end-method
/**
 * 
 * @return int
 * @param priority int
 */

public int getWlBusy (int priority ) {    
    
    int prty = priority;
      
    // verify wait list number, (priority)
    if  ((priority < 1) ||
         (priority > nbr_waitlists)) {

        // no good, use one           
        prty = 1;

   } // endif                              
     
    // addr of first waitlist
    WaitLists WL = waitlist;
    
    int i;
    
    // loop thru waitlists until the requested
    for  (i = 1; i < prty; i++) {
                           
           // get the next addr in the linked list
          WL = WL.getNext();
          
          // verify wait list addr
          if  (WL == null) {

              // no good
            return 0;

          } // endif  
    } // end-for                            
      
    // return the count of busy entries
    return WL.getWlBusy();
    
} // end-method
/**
 * 
 * @return int
 */
 
public int getWlEntries ( ) {
  
    return nbr_wl_entries;
    
} // end-method
/**
 * 

⌨️ 快捷键说明

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