搶佔先機
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 模組。