Permalink
Browse files

- JDBC_PING.serialize()/deserialize() methods use now Util.XXX() meth…

…ods to marshal, and pull them up into Discovery
  • Loading branch information...
Bela Ban
Bela Ban committed May 27, 2011
1 parent 62c0f90 commit d79637016b92233e2178a5e248255cd10c2557be
Showing with 31 additions and 49 deletions.
  1. +26 −0 src/org/jgroups/protocols/Discovery.java
  2. +5 −49 src/org/jgroups/protocols/JDBC_PING.java
@@ -499,6 +499,32 @@ protected final View makeView(Vector<Address> mbrs) {
return new View(new ViewId(local_addr), mbrs);
}
+ /**
+ * Creates a byte[] representation of the PingData, but DISCARDING the view it contains.
+ * @param data the PingData instance to serialize.
+ * @return
+ */
+ protected byte[] serializeWithoutView(PingData data) {
+ final PingData clone = new PingData(data.getAddress(), null, data.isServer(), data.getLogicalName(), data.getPhysicalAddrs());
+ try {
+ return Util.streamableToByteBuffer(clone);
+ }
+ catch(Exception e) {
+ log.error("Error", e);
+ return null;
+ }
+ }
+
+ protected PingData deserialize(final byte[] data) {
+ try {
+ return (PingData)Util.streamableFromByteBuffer(PingData.class, data);
+ }
+ catch(Exception e) {
+ log.error("Error", e);
+ return null;
+ }
+ }
+
private void sendDiscoveryResponse(Address logical_addr, List<PhysicalAddress> physical_addrs,
boolean is_server, String logical_name, Address sender) {
@@ -2,24 +2,15 @@
import org.jgroups.Address;
import org.jgroups.annotations.Property;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
+import org.jgroups.util.Util;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
+import java.sql.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
/**
* <p>Discovery protocol using a JDBC connection to a shared database.
@@ -303,41 +294,6 @@ protected void deleteSelf() throws SQLException {
delete(group_addr, ownAddress);
}
- /**
- * Creates a byte[] representation of the PingData, but DISCARDING
- * the view it contains.
- * @param data the PingData instance to serialize.
- * @return
- */
- protected byte[] serializeWithoutView(PingData data) {
- final PingData clone = new PingData(data.getAddress(), null, data.isServer(), data.getLogicalName(), data.getPhysicalAddrs());
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream( 512 );
- DataOutputStream outputStream = new DataOutputStream(byteArrayOutputStream);
- try {
- clone.writeTo(outputStream);
- } catch (IOException e) {
- //not expecting this to happen as it's an in-memory stream
- log.error("Error", e);
- }
- return byteArrayOutputStream.toByteArray();
- }
-
- protected PingData deserialize(final byte[] data) {
- final PingData pingData = new PingData();
- final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(data);
- final DataInputStream outputStream = new DataInputStream(byteArrayInputStream);
- try {
- pingData.readFrom(outputStream);
- } catch (IllegalAccessException e) {
- log.error("Error", e);
- } catch (InstantiationException e) {
- log.error("Error", e);
- } catch (IOException e) {
- // not expecting this to happen as it's an in-memory stream
- log.error("Error", e);
- }
- return pingData;
- }
protected void closeConnection(final Connection connection) {
try {

0 comments on commit d796370

Please sign in to comment.