6. mud study DriverThreadController
package driver; import java.io.IOException; public class DriverThreadContorller implements Runnable{ String driverName ; ConnectionList connectionList; public DriverThreadContorller(String name, ConnectionList connectionList) { driverName = name; this.connectionList = connectionList; System.out.println("DriverThreadContorller"); } @Override public void run() { // TODO Auto-generated method stub try { while(true){ for(Connection conn : connectionList.getConnectionList()){ driverThread(driverName,conn); } } }catch(InterruptedException e){ System.out.println("InterruptedException driver name : "+driverName); e.printStackTrace(); }catch (Exception e) { // TODO: handle exception System.out.println("Excetpion driver name : "+driverName); e.printStackTrace(); } }//run private void driverThread(String driverName,Connection conn) throws IOException, InterruptedException{ String str=""; if("input".equals(driverName) && conn.getInput().ready()){ str = conn.getInput().readLine(); if(!isNull(str)){ System.out.println("input : "+str); conn.getInputBuffer().addBuff(str); } }else if("output".equals(driverName)){ str = conn.getOutputBuffer().getBuff(); if (!isNull(str)){ System.out.println("output : "+str); conn.getOutput().println(str); } }else if("update".equals(driverName)){ //CustomBuffer cbff = conn.getInputBuffer(); str = conn.getInputBuffer().getBuff(); if(!isNull(str)){ System.out.println("update : "+str); String[] cmd = str.split(" "); if("quit".equals(cmd[0])||"exit".equals(cmd[0])){ new ConnectionBreaker(connectionList, conn); } } }//if Thread.sleep(500); } private boolean isNull(String str){ return null==str || "".equals(str); } }----------------------------------------
==============================================
exec