如何获取Tapestry5在IoC中注册的serviceId及其当前状态
import java.util.Formatter;
import java.util.List;
import org.apache.tapestry5.ioc.Registry;
import org.apache.tapestry5.ioc.RegistryBuilder;
import org.apache.tapestry5.ioc.services.ServiceActivity;
import org.apache.tapestry5.ioc.services.ServiceActivityScoreboard;
import org.apache.tapestry5.ioc.services.Status;
import org.apache.tapestry5.services.TapestryModule;
// import my.test.project.services.AppModule;
public class Test {
public static void main(String[] args) {
RegistryBuilder builder = new RegistryBuilder();
builder.add(TapestryModule.class);
// 通过add方法可以将多个module加载进来,将其中的service全部注册到IoC中
// builder.add(AppModule.class, TapestryModule.class);
Registry registry = builder.build();
registry.performRegistryStartup();
StringBuilder buffer = new StringBuilder("Startup status:\n\n");
Formatter f = new Formatter(buffer);
int unrealized = 0;
ServiceActivityScoreboard scoreboard = registry.getService(ServiceActivityScoreboard.class);
List
int longest = 0;
// One pass to find the longest name, and to count the unrealized services.
for (ServiceActivity activity : serviceActivity) {
Status status = activity.getStatus();
longest = Math.max(longest, activity.getServiceId().length());
if (status == Status.DEFINED || status == Status.VIRTUAL)
unrealized++;
}
String formatString = "%" + longest + "s: %s\n";
// A second pass to output all the services
for (ServiceActivity activity : serviceActivity) {
f.format(formatString, activity.getServiceId(), activity.getStatus().name());
}
f.format("\n%4.2f%% unrealized services (%d/%d)\n", 100. * unrealized / serviceActivity.size(), unrealized,
serviceActivity.size());
System.out.println(buffer.toString());
}
}
No comments :
Post a Comment