抢占先机
VMware 提供培训和认证,以加速您的进步。
了解更多经过几个月的发展,我很荣幸地宣布 Hyperic 4.5 的发布。 在此版本中,我们将 Hyperic 从在 JBoss 上运行的 EJB 应用程序迁移到在 Tomcat 上运行的 Spring Web 应用程序。 详细的迁移步骤在我的 将 Hyperic 从 EJB 迁移到 Spring 的案例研究 中有介绍,最初是在最近的 SpringOne 2GX 上提出的。 在这篇文章中,我想重点介绍一下我最喜欢的关于转换的一些事情。
转换后,我们能够利用 Spring 的集成测试支持来测试我们新的服务层(转换后的 EJB)及其底层 DAO。 通过简单地添加一些注释,我们能够在不到 30 秒的时间内引导整个应用程序上下文,并在一个专用事务中运行每个测试方法,该事务在测试结束时自动回滚。 事实证明,此支持对于让我们快速将开源和企业代码库中的测试覆盖率分别提高 18% 和 12% 非常有价值。
@Transactional
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath*:META-INF/spring/*-context.xml")
public class AppdefManagerTest {
@Autowired
private AppdefManager appdefManager;
@Before
public void setUp() throws Exception {
createPlatformType("TestPlatform", "test");
}
@Test
public void testGetControllablePlatformTypes() throws Exception {
Map<String, AppdefEntityID> platformTypes = appdefManager
.getControllablePlatformTypes(subject);
assertEquals(1, platformTypes.size());
assertEquals("TestPlatform", platformTypes.keySet().iterator().next());
}
}
public void publishMessage(String name, Serializable sObj) {
TopicConnection conn = null;
TopicSession session = null;
if (_ic == null)
_ic = new InitialContext();
if (_factory == null)
_factory = _ic.lookup(CONN_FACTORY_JNDI);
TopicConnectionFactory tFactory = (TopicConnectionFactory) _factory;
Topic topic = getTopic(name);
if (topic != null) {
// Now create a connection to send a message
if (_tConn != null)
conn = _tConn;
else
conn = tFactory.createTopicConnection();
if (conn == null)
_log.error("TopicConnection cannot be created");
if (_tSession != null)
session = _tSession;
else
session = conn.createTopicSession(false,
Session.AUTO_ACKNOWLEDGE);
// Create a publisher and publish the message
TopicPublisher publisher = session.createPublisher(topic);
ObjectMessage msg = session.createObjectMessage();
msg.setObject(sObj);
publisher.publish(msg);
...
}
public void publishMessage(String name, Serializable sObj) {
eventsJmsTemplate.convertAndSend(name, sObj);
}
public int getServicesCount(AuthzSubject subject) {
Statement stmt = null;
ResultSet rs = null;
Integer subjectId = subject.getId();
try {
Connection conn = getDBConn();
String sql = "SELECT COUNT(SVC.ID) FROM TBL_SERVICE";
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
if (rs.next()) {
return rs.getInt(1);
}
} catch (SQLException e) {
log.error("Caught SQL Exception finding Services by type: " + e, e);
throw new SystemException(e);
} finally {
DBUtil.closeJDBCObjects(LOG_CTX, null, stmt, rs);
}
return 0;
}
public int getServicesCount(AuthzSubject subject) {
return jdbcTemplate.queryForInt("SELECT COUNT(SVC.ID) FROM TBL_SERVICE");
}
这真是一个减肥计划! 仅通过转换为 Spring 而不更改任何功能,我们就将开源和企业代码库都减少了约 7%。
这些只是在此版本中切换到 Spring 和 Tomcat 提供的一些好处。 实在太多了,无法在一篇博文中列出!
此版本还包含对三个 VMware vFabric 平台服务的监视和管理,包括 vFabric GemFire 6.5 分布式缓存系统、RabbitMQ 企业消息传递系统 和本周发布的新 vFabric tc Server 2.1 Java 运行时服务器。 Hyperic 的先前版本中已存在对 vFabric tc Server 的支持; 但是,在 4.5 中,该插件现在与 Hyperic 发行版捆绑在一起,不再是单独下载。 请在以后的博客文章中查找有关监视 GemFire 和 RabbitMQ 的更多信息。
在迁移的同时,我们还借此机会将我们的代码存储库从 subversion 迁移到 git。 要从 git 代码存储库下载源代码,请访问 http://git.springsource.org/hq。 我们还将构建系统从 ant 切换到 maven。 现在可以从我们的 maven 存储库 http://maven.hyperic.org/release 下载开发自定义插件或功能所需的所有 Hyperic 模块。