Skip to content

Commit

Permalink
Extracted the GC info util out from UTILS, into new component Runtime…
Browse files Browse the repository at this point in the history
…Info.
  • Loading branch information
nmihajlovski committed Jan 17, 2015
1 parent 79bc10f commit f31f2e9
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 24 deletions.
49 changes: 49 additions & 0 deletions rapidoid-utils/src/main/java/org/rapidoid/util/RuntimeInfo.java
@@ -0,0 +1,49 @@
package org.rapidoid.util;

/*
* #%L
* rapidoid-utils
* %%
* Copyright (C) 2014 - 2015 Nikolche Mihajlovski
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/

import java.lang.reflect.Method;

public class RuntimeInfo {

private static final Method getGarbageCollectorMXBeans;

static {
Class<?> manFactory = U.getClassIfExists("java.lang.management.ManagementFactory");
getGarbageCollectorMXBeans = manFactory != null ? Cls.getMethod(manFactory, "getGarbageCollectorMXBeans")
: null;
}

public static String gcInfo() {
String gcinfo = "";

if (getGarbageCollectorMXBeans != null) {
// FIXME resolve rapidoid-beany dependency
// List<?> gcs = Cls.invokeStatic(getGarbageCollectorMXBeans);
// for (Object gc : gcs) {
// gcinfo += " | " + Beany.getPropValue(gc, "name") + " x" + Beany.getPropValue(gc, "collectionCount")
// + ":" + Beany.getPropValue(gc, "collectionTime") + "ms";
// }
}
return gcinfo;
}

}
24 changes: 0 additions & 24 deletions rapidoid-utils/src/main/java/org/rapidoid/util/UTILS.java
Expand Up @@ -29,7 +29,6 @@
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.lang.reflect.Method;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
Expand All @@ -40,19 +39,10 @@
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;


import org.rapidoid.beany.Beany;
import org.rapidoid.lambda.Predicate; import org.rapidoid.lambda.Predicate;


public class UTILS implements Constants { public class UTILS implements Constants {


private static final Method getGarbageCollectorMXBeans;

static {
Class<?> manFactory = U.getClassIfExists("java.lang.management.ManagementFactory");
getGarbageCollectorMXBeans = manFactory != null ? Cls.getMethod(manFactory, "getGarbageCollectorMXBeans")
: null;
}

private UTILS() { private UTILS() {
} }


Expand Down Expand Up @@ -373,20 +363,6 @@ public static <T> void filter(Collection<T> coll, Predicate<T> predicate) {
} }
} }


public static String gcInfo() {
String gcinfo = "";

if (getGarbageCollectorMXBeans != null) {
List<?> gcs = Cls.invokeStatic(getGarbageCollectorMXBeans);

for (Object gc : gcs) {
gcinfo += " | " + Beany.getPropValue(gc, "name") + " x" + Beany.getPropValue(gc, "collectionCount")
+ ":" + Beany.getPropValue(gc, "collectionTime") + "ms";
}
}
return gcinfo;
}

public static short bytesToShort(String s) { public static short bytesToShort(String s) {
ByteBuffer buf = U.buf(s); ByteBuffer buf = U.buf(s);
U.must(buf.limit() == 2); U.must(buf.limit() == 2);
Expand Down

0 comments on commit f31f2e9

Please sign in to comment.