1 16 17 package org.apache.log4j.varia; 18 19 import org.apache.log4j.Logger; 20 import org.apache.log4j.BasicConfigurator; 21 22 import java.io.IOException ; 23 import java.io.DataInputStream ; 24 import java.io.DataOutputStream ; 25 import java.net.Socket ; 26 27 38 public class Roller { 39 40 static Logger cat = Logger.getLogger(Roller.class); 41 42 43 static String host; 44 static int port; 45 46 Roller() { 48 } 49 50 56 public 57 static 58 void main(String argv[]) { 59 60 BasicConfigurator.configure(); 61 62 if(argv.length == 2) 63 init(argv[0], argv[1]); 64 else 65 usage("Wrong number of arguments."); 66 67 roll(); 68 } 69 70 static 71 void usage(String msg) { 72 System.err.println(msg); 73 System.err.println( "Usage: java " + Roller.class.getName() + 74 "host_name port_number"); 75 System.exit(1); 76 } 77 78 static 79 void init(String hostArg, String portArg) { 80 host = hostArg; 81 try { 82 port = Integer.parseInt(portArg); 83 } 84 catch(java.lang.NumberFormatException e) { 85 usage("Second argument "+portArg+" is not a valid integer."); 86 } 87 } 88 89 static 90 void roll() { 91 try { 92 Socket socket = new Socket (host, port); 93 DataOutputStream dos = new DataOutputStream (socket.getOutputStream()); 94 DataInputStream dis = new DataInputStream (socket.getInputStream()); 95 dos.writeUTF(ExternallyRolledFileAppender.ROLL_OVER); 96 String rc = dis.readUTF(); 97 if(ExternallyRolledFileAppender.OK.equals(rc)) { 98 cat.info("Roll over signal acknowledged by remote appender."); 99 } else { 100 cat.warn("Unexpected return code "+rc+" from remote entity."); 101 System.exit(2); 102 } 103 } catch(IOException e) { 104 cat.error("Could not send roll signal on host "+host+" port "+port+" .", 105 e); 106 System.exit(2); 107 } 108 System.exit(0); 109 } 110 } 111 | Popular Tags |