| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
package com.google.inject.tools.jmx; |
| 18 |
|
|
| 19 |
|
import com.google.inject.Binding; |
| 20 |
|
import com.google.inject.Guice; |
| 21 |
|
import com.google.inject.Injector; |
| 22 |
|
import com.google.inject.Key; |
| 23 |
|
import com.google.inject.Module; |
| 24 |
|
import java.lang.annotation.Annotation; |
| 25 |
|
import java.lang.management.ManagementFactory; |
| 26 |
|
import javax.management.MBeanServer; |
| 27 |
|
import javax.management.MalformedObjectNameException; |
| 28 |
|
import javax.management.ObjectName; |
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
@author |
| 34 |
|
|
|
|
|
| 0% |
Uncovered Elements: 36 (36) |
Complexity: 10 |
Complexity Density: 0.38 |
|
| 35 |
|
public class Manager { |
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
@link |
| 40 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 41 |
0
|
public static void manage(... |
| 42 |
|
String domain, |
| 43 |
|
Injector injector) { |
| 44 |
0
|
manage(ManagementFactory.getPlatformMBeanServer(), domain, injector); |
| 45 |
|
} |
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
@link |
| 50 |
|
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 6 |
Complexity Density: 0.4 |
|
| 51 |
0
|
public static void manage(MBeanServer server, String domain,... |
| 52 |
|
Injector injector) { |
| 53 |
|
|
| 54 |
0
|
for (Binding<?> binding : injector.getBindings().values()) { |
| 55 |
|
|
| 56 |
|
|
| 57 |
0
|
StringBuilder name = new StringBuilder(); |
| 58 |
0
|
name.append(domain).append(":"); |
| 59 |
0
|
Key<?> key = binding.getKey(); |
| 60 |
0
|
name.append("type=").append(quote(key.getTypeLiteral().toString())); |
| 61 |
0
|
Annotation annotation = key.getAnnotation(); |
| 62 |
0
|
if (annotation != null) { |
| 63 |
0
|
name.append(",annotation=").append(quote(annotation.toString())); |
| 64 |
|
} |
| 65 |
|
else { |
| 66 |
0
|
Class<? extends Annotation> annotationType = key.getAnnotationType(); |
| 67 |
0
|
if (annotationType != null) { |
| 68 |
0
|
name.append(",annotation=") |
| 69 |
|
.append(quote("@" + annotationType.getName())); |
| 70 |
|
} |
| 71 |
|
} |
| 72 |
|
|
| 73 |
0
|
try { |
| 74 |
0
|
server.registerMBean(new ManagedBinding(binding), |
| 75 |
|
new ObjectName(name.toString())); |
| 76 |
|
} |
| 77 |
|
catch (MalformedObjectNameException e) { |
| 78 |
0
|
throw new RuntimeException("Bad object name: " |
| 79 |
|
+ name.toString(), e); |
| 80 |
|
} |
| 81 |
|
catch (Exception e) { |
| 82 |
0
|
throw new RuntimeException(e); |
| 83 |
|
} |
| 84 |
|
} |
| 85 |
|
} |
| 86 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 87 |
0
|
static String quote(String value) {... |
| 88 |
|
|
| 89 |
0
|
return ObjectName.quote(value).replace(',', ';'); |
| 90 |
|
} |
| 91 |
|
|
| 92 |
|
|
| 93 |
|
|
| 94 |
|
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 2 |
Complexity Density: 0.22 |
|
| 95 |
0
|
public static void main(String[] args) throws Exception {... |
| 96 |
0
|
if (args.length != 1) { |
| 97 |
0
|
System.err.println("Usage: java -Dcom.sun.management.jmxremote " |
| 98 |
|
+ Manager.class.getName() + " [module class name]"); |
| 99 |
0
|
System.err.println("Then run 'jconsole' to connect."); |
| 100 |
0
|
System.exit(1); |
| 101 |
|
} |
| 102 |
|
|
| 103 |
0
|
Module module = (Module) Class.forName(args[0]).newInstance(); |
| 104 |
0
|
Injector injector = Guice.createInjector(module); |
| 105 |
|
|
| 106 |
0
|
manage(args[0], injector); |
| 107 |
|
|
| 108 |
0
|
System.out.println("Press Ctrl+C to exit..."); |
| 109 |
|
|
| 110 |
|
|
| 111 |
0
|
Thread.sleep(Long.MAX_VALUE); |
| 112 |
|
} |
| 113 |
|
} |