领先一步
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运行时服务器。vFabric tc Server的支持在Hyperic的早期版本中已经存在;然而,在4.5版本中,插件现在与Hyperic发行版捆绑在一起,不再是单独下载。请关注未来的博客文章,获取更多关于监控GemFire和RabbitMQ的信息。
在迁移过程中,我们还借此机会将代码仓库从Subversion迁移到了Git。要从Git代码仓库下载源代码,请访问http://git.springsource.org/hq。我们还将构建系统从Ant切换到了Maven。现在,开发自定义插件或功能所需的所有Hyperic模块都可以从我们的Maven仓库http://maven.hyperic.org/release下载。