Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.32 KB | None | 0 0
  1. //Lab 05 Question 2
  2. //Pair 3
  3. //Chris & Kurtis
  4. //import connectionStuff.*;
  5.  
  6. public class ConnectionManager{
  7.  
  8.     static Connection[] cArray = new Connection[5];
  9.  
  10.     static {
  11.         cArray[0] = Connection.makeConnection();
  12.         cArray[1] = Connection.makeConnection();
  13.         cArray[2] = Connection.makeConnection();
  14.         cArray[3] = Connection.makeConnection();
  15.         cArray[4] = Connection.makeConnection();
  16.     }
  17.  
  18.  
  19.     public static Connection getConnection() {
  20.         Connection tempC = null;
  21.  
  22.         for (int i = 0; i < cArray.length; i++) {
  23.             if (i == 6){
  24.                 System.out.println("All connections are in use! Please try again later.");
  25.                 break;
  26.             }
  27.             String temp = cArray[i].toString();
  28.             if (temp.equals("connected")){
  29.                 System.out.println("This connection is in use");
  30.             }
  31.             else if (temp.equals("disconnected")){
  32.                 cArray[i].initiateService();
  33.                 System.out.println("You've aquired connection ID: "+ i);
  34.                 tempC = cArray[i];
  35.                 break;
  36.             }
  37.             else if(temp.equals("[An ERROR has occurred]")){
  38.                 System.out.println("Error with this connection");
  39.             }
  40.         }
  41.         return tempC;
  42.     }
  43.  
  44.     public static void setConnection(int ConnectionID){
  45.         System.out.println("You have closed connection ID: "+ ConnectionID);
  46.         cArray[ConnectionID].endService();
  47.     }
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement