Permalink
Browse files

tidied up formatting

  • Loading branch information...
1 parent 4ee50bd commit 9f40304bf65da3976624f8cfb22742a62a11a5ef @djpowell djpowell committed Oct 18, 2009
@@ -14,90 +14,90 @@
import net.djpowell.liverepl.client.Main;
public class Agent {
-
- private static ClassLoader pushClassLoader(List<URL> urls) {
- TRC.fine("Creating new classloader with: " + urls);
- ClassLoader old = Thread.currentThread().getContextClassLoader();
- TRC.fine("Old classloader: " + old);
- URLClassLoader withClojure = new URLClassLoader(urls.toArray(new URL[urls.size()]), old); // TODO
- Thread.currentThread().setContextClassLoader(withClojure);
- return old;
- }
-
- private static void popClassLoader(ClassLoader old) {
- TRC.fine("Restoring old context classloader");
- Thread.currentThread().setContextClassLoader(old);
- }
+
+ private static ClassLoader pushClassLoader(List<URL> urls) {
+ TRC.fine("Creating new classloader with: " + urls);
+ ClassLoader old = Thread.currentThread().getContextClassLoader();
+ TRC.fine("Old classloader: " + old);
+ URLClassLoader withClojure = new URLClassLoader(urls.toArray(new URL[urls.size()]), old); // TODO
+ Thread.currentThread().setContextClassLoader(withClojure);
+ return old;
+ }
+
+ private static void popClassLoader(ClassLoader old) {
+ TRC.fine("Restoring old context classloader");
+ Thread.currentThread().setContextClassLoader(old);
+ }
- private static boolean isClojureLoaded() {
- try {
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- cl.loadClass("clojure.lang.RT");
- return true;
- } catch (ClassNotFoundException e) {
- return false;
- }
- }
-
- public static void agentmain(String agentArgs, Instrumentation inst) {
- TRC.fine("Started Attach agent");
-
- StringTokenizer stok = new StringTokenizer(agentArgs, "\n");
- if (stok.countTokens() != 3) {
- throw new RuntimeException("Invalid parameters: " + agentArgs);
- }
-
- int port = Integer.parseInt(stok.nextToken());
- TRC.fine("Port: " + port);
- String clojurePath = stok.nextToken();
- String serverPath = stok.nextToken();
-
- boolean clojureLoaded = isClojureLoaded();
- TRC.fine("Clojure is " + (clojureLoaded ? "" : "not ") + "loaded");
+ private static boolean isClojureLoaded() {
+ try {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ cl.loadClass("clojure.lang.RT");
+ return true;
+ } catch (ClassNotFoundException e) {
+ return false;
+ }
+ }
+
+ public static void agentmain(String agentArgs, Instrumentation inst) {
+ TRC.fine("Started Attach agent");
+
+ StringTokenizer stok = new StringTokenizer(agentArgs, "\n");
+ if (stok.countTokens() != 3) {
+ throw new RuntimeException("Invalid parameters: " + agentArgs);
+ }
+
+ int port = Integer.parseInt(stok.nextToken());
+ TRC.fine("Port: " + port);
+ String clojurePath = stok.nextToken();
+ String serverPath = stok.nextToken();
+
+ boolean clojureLoaded = isClojureLoaded();
+ TRC.fine("Clojure is " + (clojureLoaded ? "" : "not ") + "loaded");
- List<URL> urls;
- if (clojureLoaded) {
- urls = getJarUrls(serverPath);
- } else {
- urls = getJarUrls(clojurePath, serverPath);
- }
-
- ClassLoader old = pushClassLoader(urls);
- try {
- if (!clojureLoaded) { // if clojure wasn't loaded before, print current status
- TRC.fine("Clojure is " + (isClojureLoaded() ? "" : "not ") + "loaded");
- }
- startRepl(port);
- } finally {
- popClassLoader(old);
- }
- }
+ List<URL> urls;
+ if (clojureLoaded) {
+ urls = getJarUrls(serverPath);
+ } else {
+ urls = getJarUrls(clojurePath, serverPath);
+ }
+
+ ClassLoader old = pushClassLoader(urls);
+ try {
+ if (!clojureLoaded) { // if clojure wasn't loaded before, print current status
+ TRC.fine("Clojure is " + (isClojureLoaded() ? "" : "not ") + "loaded");
+ }
+ startRepl(port);
+ } finally {
+ popClassLoader(old);
+ }
+ }
- private static List<URL> getJarUrls(String... paths) {
- List<URL> urls = new ArrayList<URL>();
- try {
- for (String path : paths) {
- URL url = new File(path).toURI().toURL();
- urls.add(url);
- }
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- return urls;
- }
+ private static List<URL> getJarUrls(String... paths) {
+ List<URL> urls = new ArrayList<URL>();
+ try {
+ for (String path : paths) {
+ URL url = new File(path).toURI().toURL();
+ urls.add(url);
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ return urls;
+ }
- private static void startRepl(int port) {
- // avoids making load-time references to Clojure classes from the system classloader
- try {
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- Class<?> repl = Class.forName("net.djpowell.liverepl.server.Repl", true, cl);
- Method method = repl.getMethod("main", InetAddress.class, Integer.TYPE);
- method.invoke(null, Main.LOCALHOST, port);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
+ private static void startRepl(int port) {
+ // avoids making load-time references to Clojure classes from the system classloader
+ try {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ Class<?> repl = Class.forName("net.djpowell.liverepl.server.Repl", true, cl);
+ Method method = repl.getMethod("main", InetAddress.class, Integer.TYPE);
+ method.invoke(null, Main.LOCALHOST, port);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
- private static final Logger TRC = Logger.getLogger(Agent.class.getName());
+ private static final Logger TRC = Logger.getLogger(Agent.class.getName());
}
@@ -13,70 +13,70 @@
public class Console {
- private static String NEWLINE = System.getProperty("line.separator");
-
- public static void main(InetAddress host, int port) throws Exception {
- final BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));
- final Writer cout = new OutputStreamWriter(System.out);
- Socket s = new Socket(host, port);
- try {
- final Thread main = Thread.currentThread();
- final Reader sin = new InputStreamReader(s.getInputStream());
- final Writer sout = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
+ private static String NEWLINE = System.getProperty("line.separator");
+
+ public static void main(InetAddress host, int port) throws Exception {
+ final BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));
+ final Writer cout = new OutputStreamWriter(System.out);
+ Socket s = new Socket(host, port);
+ try {
+ final Thread main = Thread.currentThread();
+ final Reader sin = new InputStreamReader(s.getInputStream());
+ final Writer sout = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
- Thread ch = new Thread("ConsoleHandler") {
- @Override
- public void run() {
- try {
- for (;;) {
- // use line-based i/o for reading from the keyboard
- String line = cin.readLine();
- if (line == null) break;
- sout.write(line + NEWLINE);
- sout.flush();
- }
- } catch (IOException e) {
- TRC.fine(e.getMessage());
- } finally {
- main.interrupt();
- }
- }
- };
- ch.start();
+ Thread ch = new Thread("ConsoleHandler") {
+ @Override
+ public void run() {
+ try {
+ for (;;) {
+ // use line-based i/o for reading from the keyboard
+ String line = cin.readLine();
+ if (line == null) break;
+ sout.write(line + NEWLINE);
+ sout.flush();
+ }
+ } catch (IOException e) {
+ TRC.fine(e.getMessage());
+ } finally {
+ main.interrupt();
+ }
+ }
+ };
+ ch.start();
- Thread sh = new Thread("SocketHandler") {
- @Override
- public void run() {
- try {
- for (;;) {
- // use character based i/o for printing server responses
- int ic = sin.read();
- if (ic == -1) break;
- char c = (char) ic;
- cout.write(c);
- cout.flush();
- }
- } catch (IOException e) {
- TRC.fine(e.getMessage());
- } finally {
- main.interrupt();
- }
- }
- };
- sh.start();
-
- // block until both threads finish
- try {
- sh.join();
- ch.join();
- } catch (InterruptedException e) {
- s.close();
- }
- } finally {
- s.close();
- }
- }
-
- private static final Logger TRC = Logger.getLogger(Console.class.getName());
+ Thread sh = new Thread("SocketHandler") {
+ @Override
+ public void run() {
+ try {
+ for (;;) {
+ // use character based i/o for printing server responses
+ int ic = sin.read();
+ if (ic == -1) break;
+ char c = (char) ic;
+ cout.write(c);
+ cout.flush();
+ }
+ } catch (IOException e) {
+ TRC.fine(e.getMessage());
+ } finally {
+ main.interrupt();
+ }
+ }
+ };
+ sh.start();
+
+ // block until both threads finish
+ try {
+ sh.join();
+ ch.join();
+ } catch (InterruptedException e) {
+ s.close();
+ }
+ } finally {
+ s.close();
+ }
+ }
+
+ private static final Logger TRC = Logger.getLogger(Console.class.getName());
}
Oops, something went wrong.

0 comments on commit 9f40304

Please sign in to comment.