From 30c1d35714245109e0fa1fadc738c8fe5f4c6e75 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Sat, 24 Feb 2007 16:19:17 +0000 Subject: [PATCH] Make Java objects returned by Sigar class Serializable --- ChangeLog | 4 ++++ bindings/java/src/jni/generate.pl | 22 +++++++++++++++++-- .../java/src/org/hyperic/sigar/CpuPerc.java | 5 ++++- .../java/src/org/hyperic/sigar/FileInfo.java | 6 +++-- .../java/src/org/hyperic/sigar/NetStat.java | 4 +++- .../src/org/hyperic/sigar/NfsFileSystem.java | 4 +++- 6 files changed, 38 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 31b2f034..9ffa374e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2007-02-24 Doug MacEachern + + * Make Java objects returned by Sigar class Serializable + 2007-02-21 Doug MacEachern * Perl binding updates diff --git a/bindings/java/src/jni/generate.pl b/bindings/java/src/jni/generate.pl index ede78ffe..4c687f33 100644 --- a/bindings/java/src/jni/generate.pl +++ b/bindings/java/src/jni/generate.pl @@ -28,6 +28,15 @@ sub supported_platforms { return join ", ", @platforms; } +sub hash { + use integer; + my $hash = 0; + for (split //, shift) { + $hash = $hash*31 + ord $_; + } + return $hash; +} + #this script generates jni code and java classes for the following table my %classes = ( @@ -1395,6 +1404,13 @@ EOF my $cache_field_ids = 1; + my $uid = 0; + + for my $field (@$fields) { + $field->{type} ||= 'Long'; + $uid += hash($field->{type}) + hash($field->{name}); + } + print JFH <{type} || 'Long'; + my $type = $field->{type}; my $name = $field->{name}; my $member = $field->{member} || $name; my $desc = $field->{desc} || $name; diff --git a/bindings/java/src/org/hyperic/sigar/CpuPerc.java b/bindings/java/src/org/hyperic/sigar/CpuPerc.java index 49c02bd0..67520761 100644 --- a/bindings/java/src/org/hyperic/sigar/CpuPerc.java +++ b/bindings/java/src/org/hyperic/sigar/CpuPerc.java @@ -21,7 +21,10 @@ package org.hyperic.sigar; /** * CPU percentage usage */ -public class CpuPerc { +public class CpuPerc implements java.io.Serializable { + + private static final long serialVersionUID = 02242007L; + private double user; private double sys; private double nice; diff --git a/bindings/java/src/org/hyperic/sigar/FileInfo.java b/bindings/java/src/org/hyperic/sigar/FileInfo.java index 5ee7769b..65f904a0 100644 --- a/bindings/java/src/org/hyperic/sigar/FileInfo.java +++ b/bindings/java/src/org/hyperic/sigar/FileInfo.java @@ -22,13 +22,15 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; -public class FileInfo extends FileAttrs { +public class FileInfo extends FileAttrs implements java.io.Serializable { + + private static final long serialVersionUID = 02242007L; private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("MMM dd HH:mm"); String name; - private Sigar sigar; + private transient Sigar sigar; private boolean dirStatEnabled = false; private DirStat stat = null; private boolean lstat; diff --git a/bindings/java/src/org/hyperic/sigar/NetStat.java b/bindings/java/src/org/hyperic/sigar/NetStat.java index 5eeff79a..503d7213 100644 --- a/bindings/java/src/org/hyperic/sigar/NetStat.java +++ b/bindings/java/src/org/hyperic/sigar/NetStat.java @@ -18,7 +18,9 @@ package org.hyperic.sigar; -public class NetStat { +public class NetStat implements java.io.Serializable { + + private static final long serialVersionUID = 02242007L; protected int[] tcpStates; protected int tcpInboundTotal, tcpOutboundTotal; diff --git a/bindings/java/src/org/hyperic/sigar/NfsFileSystem.java b/bindings/java/src/org/hyperic/sigar/NfsFileSystem.java index 640576b9..0dc1ca7f 100644 --- a/bindings/java/src/org/hyperic/sigar/NfsFileSystem.java +++ b/bindings/java/src/org/hyperic/sigar/NfsFileSystem.java @@ -21,7 +21,9 @@ package org.hyperic.sigar; import java.net.InetAddress; import java.net.UnknownHostException; -public class NfsFileSystem extends FileSystem { +public class NfsFileSystem extends FileSystem implements java.io.Serializable { + + private static final long serialVersionUID = 02242007L; private static final int NFS_PROGRAM = 100003;