Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Lab 05 Question 2
- //Pair 3
- //Chris & Kurtis
- //import connectionStuff.*;
- public class ConnectionManager{
- static Connection[] cArray = new Connection[5];
- static {
- cArray[0] = Connection.makeConnection();
- cArray[1] = Connection.makeConnection();
- cArray[2] = Connection.makeConnection();
- cArray[3] = Connection.makeConnection();
- cArray[4] = Connection.makeConnection();
- }
- public static Connection getConnection() {
- Connection tempC = null;
- for (int i = 0; i < cArray.length; i++) {
- if (i == 6){
- System.out.println("All connections are in use! Please try again later.");
- break;
- }
- String temp = cArray[i].toString();
- if (temp.equals("connected")){
- System.out.println("This connection is in use");
- }
- else if (temp.equals("disconnected")){
- cArray[i].initiateService();
- System.out.println("You've aquired connection ID: "+ i);
- tempC = cArray[i];
- break;
- }
- else if(temp.equals("[An ERROR has occurred]")){
- System.out.println("Error with this connection");
- }
- }
- return tempC;
- }
- public static void setConnection(int ConnectionID){
- System.out.println("You have closed connection ID: "+ ConnectionID);
- cArray[ConnectionID].endService();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement