SlideShare une entreprise Scribd logo
1  sur  21
Télécharger pour lire hors ligne
HDF-EOS Java Application
Programming Interfaces
Genong (Eugene) Yu, Ph.D.
Research associate

Liping Di, Ph.D.
Professor & Director of CSISS
{gyu, ldi}@gmu.edu

November 28-30, 2006

HDF and HDF-EOS Workshop X,
Upper Marlboro, MD
Outline
• Why Java API interfaces?
• Java API interfaces
– Variable consideration

•
•
•
•

Java Object wrap-up
Performance consideration
Applications
Problem
– Memory management
Demand
• Distribution systems over the Web
– Java-based server
• Apache Tomcat

• Manipulation of data for the Web
application
– Re-projection service
– Classification service
– Re-format service
Bridging Java Program and C/C++ library
The Problem
HDF-EOS
HDF-EOS

HDF-EOS
HDF-EOS

HDF-EOS
HDF-EOS

HDF JNI API

• HDF-EOS library – in C/C++ library
• All functions to manipulate grid and
point are written in C
• Primer for HDF-EOS is for C
• HDF JNI libraries are available
• Possible approach

Java Reader

• Rewrite the program in Java

WEB APPLICATION

• Pros: better for Java environment
The Solution
HDF-EOS
HDF-EOS

HDF-EOS
HDF-EOS

HDF-EOS
HDF-EOS

HDF-EOS / HDF JNI API

Java Reader
WEB APPLICATION

• Cons: enormous work and need
to keep track of revision
• Call the library directly through JNI
• Pros: manageable work and
efficient re-use
• Cons: memory management,
debugging
How JNI works (1)
• Java interface
– public static native int GDopen(String filename, int
access) throws HDFEOSException;
– Load library
• System.loadLibrary("jhdfeos4");

• Compile the above code
– javac HDFEOSLibrary.java

• Create header File
– javah -jni edu
How JNI works (2)
• Create the library in C/C++
– Template
• JNIEXPORT void JNICALL Java_ClassName_MethodName
(JNIEnv *env, jobject obj) {
• //Implement Native Method Here
• }

– Example
• JNIEXPORT jint JNICALL
Java_edu_gmu_laits_hdfeos_HDFEOSLibrary_SWdupregion
• (JNIEnv *env, jclass class, jint oldregionID)
• {
•
int32 regionID;
•
regionID=SWdupregion((int32)oldregionID);
•
return (jint)regionID;
• }
Tasks to enable the JNI
• To access a C library from a Java
program, four tasks must be completed:
– Declare appropriate “native” methods in Java
classes
– Write “interface” code for each native method
to implement the JNI C or C++ standard
– compile the JNI “interface” (C or C++) to
create a JNI library
– deploy the Java classes and the JNI library on
the system
Mapping types (1)
• Interchangeable types
Native type
(C/C++)

Java Language Description
Type

HDF/HDFEOS

bool

jboolean

Unsigned 8 bits

intn, uint8

byte

jbyte

Signed 8 bits

int8

char

jchar

Unsigned 16 bits uint16

short

jshort

Signed 16 bits

int16

long

jint

Signed 32 bits

int32

long long

jlong

Signed 64 bits

int64

Float

jfloat

Float 32 bits

float32

Double

jdouble

Float 64 bits

float64
Mapping types (2)
•

String
–

Wrong
• JNIEXPORT jint JNICALL Java_edu_gmu_laits_hdfeos_HDFEOSLibrary_SWcreate
• (JNIEnv *env, jclass class, jint file_id, jstring swath_name)
• {
• return SWcreate( (int32)file_id, (char *) swath_name);
• }

–

Correct
• JNIEXPORT jint JNICALL Java_edu_gmu_laits_hdfeos_HDFEOSLibrary_SWcreate
• (JNIEnv *env, jclass class, jint file_id, jstring swath_name)
• {
• char *s_filename;
• int32 swath_id;
• s_filename = (char *) (*env)->GetStringUTFChars( env, swath_name, 0);
• swath_id = SWcreate( (int32)file_id, (char *)s_filename );
• (*env)->ReleaseStringUTFChars(env, swath_name, s_filename );
• return (jint)swath_id;
• }
Mapping types (3)
•

Array
–

–

Wrong
• JNIEXPORT jboolean JNICALL
Java_edu_gmu_laits_hdfeos_HDFEOSLibrary_GDorigininfo
• (JNIEnv *env, jclass class, jint gridID, jintArray origincode)
• {
•
int32 status;
•
status= GDorigininfo((int32)gridID,(int32 *)origincode);
•
if (status==-1) return JNI_FALSE;
•
else return JNI_TRUE;
• }
Correct
•
•
•
•
•
•
•
•
•
•
•

JNIEXPORT jboolean JNICALL Java_edu_gmu_laits_hdfeos_HDFEOSLibrary_GDorigininfo
(JNIEnv *env, jclass class, jint gridID, jintArray origincode)
{
int32 *i_origincode;
int32 status;
i_origincode=(int32 *)(*env)->GetIntArrayElements(env,origincode,0);
status=GDorigininfo((int32)gridID,i_origincode);
(*env)->ReleaseIntArrayElements(env,origincode,(jint *)i_origincode,0);
if (status==-1) return JNI_FALSE;
else return JNI_TRUE;
}
Mapping types (4)
• Pointer
– In C
• intn SWattrinfo(int32 swathID, char *attrname, int32
* numbertype, int32 *count);

– In Java
• public static native boolean SWattrinfo(int swathID,
String attrname, int[] numbertype, int[] count) throws
HDFEOSException;
The HDF-EOS library
• Interface level
– One class to hold all “native” methods
– One C “interface” library – e.g. jhdfeos4 (dll,
so)
– One-to-one
Hierarchy of objects
dataset
GeoDataset
RasterDataset

HESwathDataset

HEGridDataset

To be implemented

HEGrid
HEGridField

HEGridFieldBand2d

VectorDataset

HEPointDataset
To be implemented
Thread safe vs. efficiency
• Model 1: Access & close
• Model 2: Open – access – close
HEGridDataset

HEGridDataset

HEGrid

HEGrid2

HEGridField

HEGridField2

HEGridFieldBand2d

HEGridFieldBand2d2

Model 1

Model 2
Applications (1)
• Web services
– Conversion
http://laits.gmu.edu:18080/DataMining/HDFEOS2ARFF?WSDL
– Conversion
http://laits.gmu.edu:18080/DataMining/ARFF2HDFEOS2?WSDL
– Training
http://laits.gmu.edu:18080/DataMining/LogisticRegressionTrainer
?WSDL
– Classification
http://laits.gmu.edu:18080/DataMining/LogisticRegressionClassif
ier?WSDL
– Regression
http://laits.gmu.edu:18080/DataMining/LogisticRegressor?WSDL

• Test pages
http://laits.gmu.edu:18080/DataMiningClientWeb/
Applications (2)
Limitations to the JNI approach
• Limitations
– JNI is not an easy API;
– Invocation: only applications and signed applets can invoke the
JNI;
– Portability: No
• compile different set of libraries and dynamically load

– Memory management: no garbage collection
• Careful to manage memory and exception in C
• Timely re-start Tomcat server (not a good solution)

– Debugging difficulty: error checking is a MUST or it has the
potential
• to crash the server
• to left dead thread
• to cause memory leak
Conclusions
• The library is available at
– http://laits.gmu.edu/~gyu/HDFEOS/
Future work
• Continue on updating the interface
• Work on HDF5-EOS
• Refine the object with considerations of
performance and usability
References
• JNI specification
http://java.sun.com/j2se/1.5.0/docs/guide/j
ni/spec/jniTOC.html
• Java Native Interface: Programmer’s
Guide and Specification
http://java.sun.com/docs/books/jni/
Acknowledgements
• The work was supported partially with grants from the
NASA Earth Science Data and Information System
Project (ESDISP) (NCC5-645, PI: Dr. Liping Di), NASA
Earth Science Technology Office (ESTO) (NAG-13409,
PI: Dr. Liping Di), NASA REASoN program
(NNG04GE61A, PI: Dr. Liping Di), and National
Geospatial-intelligence Agency (NGA) University
Research Initiative (NURI) (HM1582-04-1-2021, PI: Dr.
Liping Di).
• Thanks to Dr. Peisheng Zhao, Dr. Aijun Chen, Dr. Yuqi
Bai, Mr. Yaxing Wei, and other colleagues at Center for
Spatial Information Science and System, George Mason
University, for their inputs and contributions.

Contenu connexe

Similaire à HDF-EOS Java Application Programming Interfaces

Geospatial web services using little-known GDAL features and modern Perl midd...
Geospatial web services using little-known GDAL features and modern Perl midd...Geospatial web services using little-known GDAL features and modern Perl midd...
Geospatial web services using little-known GDAL features and modern Perl midd...
Ari Jolma
 
Java jdk-update-nov10-sde-v3m
Java jdk-update-nov10-sde-v3mJava jdk-update-nov10-sde-v3m
Java jdk-update-nov10-sde-v3m
Steve Elliott
 
1 Project 2 Introduction - the SeaPort Project seri.docx
1  Project 2 Introduction - the SeaPort Project seri.docx1  Project 2 Introduction - the SeaPort Project seri.docx
1 Project 2 Introduction - the SeaPort Project seri.docx
honey725342
 

Similaire à HDF-EOS Java Application Programming Interfaces (20)

Arabidopsis Information Portal, Developer Workshop 2014, Introduction
Arabidopsis Information Portal, Developer Workshop 2014, IntroductionArabidopsis Information Portal, Developer Workshop 2014, Introduction
Arabidopsis Information Portal, Developer Workshop 2014, Introduction
 
gRPC, GraphQL, REST - Which API Tech to use - API Conference Berlin oct 20
gRPC, GraphQL, REST - Which API Tech to use - API Conference Berlin oct 20gRPC, GraphQL, REST - Which API Tech to use - API Conference Berlin oct 20
gRPC, GraphQL, REST - Which API Tech to use - API Conference Berlin oct 20
 
Java 7 - New Features - by Mihail Stoynov and Svetlin Nakov
Java 7 - New Features - by Mihail Stoynov and Svetlin NakovJava 7 - New Features - by Mihail Stoynov and Svetlin Nakov
Java 7 - New Features - by Mihail Stoynov and Svetlin Nakov
 
Enhancing Domain Specific Language Implementations Through Ontology
Enhancing Domain Specific Language Implementations Through OntologyEnhancing Domain Specific Language Implementations Through Ontology
Enhancing Domain Specific Language Implementations Through Ontology
 
Android networking-2
Android networking-2Android networking-2
Android networking-2
 
Grails 101
Grails 101Grails 101
Grails 101
 
NetCDF and HDF5
NetCDF and HDF5NetCDF and HDF5
NetCDF and HDF5
 
Alive and Well with Java 8
Alive and Well with Java 8Alive and Well with Java 8
Alive and Well with Java 8
 
Geospatial web services using little-known GDAL features and modern Perl midd...
Geospatial web services using little-known GDAL features and modern Perl midd...Geospatial web services using little-known GDAL features and modern Perl midd...
Geospatial web services using little-known GDAL features and modern Perl midd...
 
Building collaborative workflows for scientific data
Building collaborative workflows for scientific dataBuilding collaborative workflows for scientific data
Building collaborative workflows for scientific data
 
Groovy In the Cloud
Groovy In the CloudGroovy In the Cloud
Groovy In the Cloud
 
Java jdk-update-nov10-sde-v3m
Java jdk-update-nov10-sde-v3mJava jdk-update-nov10-sde-v3m
Java jdk-update-nov10-sde-v3m
 
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
 
State of GeoServer 2.10
State of GeoServer 2.10State of GeoServer 2.10
State of GeoServer 2.10
 
Golang workshop - Mindbowser
Golang workshop - MindbowserGolang workshop - Mindbowser
Golang workshop - Mindbowser
 
HTML5 - The Python Angle (PyCon Ireland 2010)
HTML5 - The Python Angle (PyCon Ireland 2010)HTML5 - The Python Angle (PyCon Ireland 2010)
HTML5 - The Python Angle (PyCon Ireland 2010)
 
Hadoop 101 for bioinformaticians
Hadoop 101 for bioinformaticiansHadoop 101 for bioinformaticians
Hadoop 101 for bioinformaticians
 
1 Project 2 Introduction - the SeaPort Project seri.docx
1  Project 2 Introduction - the SeaPort Project seri.docx1  Project 2 Introduction - the SeaPort Project seri.docx
1 Project 2 Introduction - the SeaPort Project seri.docx
 
01 java intro
01 java intro01 java intro
01 java intro
 
Porting VisualWorks code to Pharo
Porting VisualWorks code to PharoPorting VisualWorks code to Pharo
Porting VisualWorks code to Pharo
 

Plus de The HDF-EOS Tools and Information Center

Plus de The HDF-EOS Tools and Information Center (20)

Cloud-Optimized HDF5 Files
Cloud-Optimized HDF5 FilesCloud-Optimized HDF5 Files
Cloud-Optimized HDF5 Files
 
Accessing HDF5 data in the cloud with HSDS
Accessing HDF5 data in the cloud with HSDSAccessing HDF5 data in the cloud with HSDS
Accessing HDF5 data in the cloud with HSDS
 
The State of HDF
The State of HDFThe State of HDF
The State of HDF
 
Highly Scalable Data Service (HSDS) Performance Features
Highly Scalable Data Service (HSDS) Performance FeaturesHighly Scalable Data Service (HSDS) Performance Features
Highly Scalable Data Service (HSDS) Performance Features
 
Creating Cloud-Optimized HDF5 Files
Creating Cloud-Optimized HDF5 FilesCreating Cloud-Optimized HDF5 Files
Creating Cloud-Optimized HDF5 Files
 
HDF5 OPeNDAP Handler Updates, and Performance Discussion
HDF5 OPeNDAP Handler Updates, and Performance DiscussionHDF5 OPeNDAP Handler Updates, and Performance Discussion
HDF5 OPeNDAP Handler Updates, and Performance Discussion
 
Hyrax: Serving Data from S3
Hyrax: Serving Data from S3Hyrax: Serving Data from S3
Hyrax: Serving Data from S3
 
Accessing Cloud Data and Services Using EDL, Pydap, MATLAB
Accessing Cloud Data and Services Using EDL, Pydap, MATLABAccessing Cloud Data and Services Using EDL, Pydap, MATLAB
Accessing Cloud Data and Services Using EDL, Pydap, MATLAB
 
HDF - Current status and Future Directions
HDF - Current status and Future DirectionsHDF - Current status and Future Directions
HDF - Current status and Future Directions
 
HDFEOS.org User Analsys, Updates, and Future
HDFEOS.org User Analsys, Updates, and FutureHDFEOS.org User Analsys, Updates, and Future
HDFEOS.org User Analsys, Updates, and Future
 
HDF - Current status and Future Directions
HDF - Current status and Future Directions HDF - Current status and Future Directions
HDF - Current status and Future Directions
 
H5Coro: The Cloud-Optimized Read-Only Library
H5Coro: The Cloud-Optimized Read-Only LibraryH5Coro: The Cloud-Optimized Read-Only Library
H5Coro: The Cloud-Optimized Read-Only Library
 
MATLAB Modernization on HDF5 1.10
MATLAB Modernization on HDF5 1.10MATLAB Modernization on HDF5 1.10
MATLAB Modernization on HDF5 1.10
 
HDF for the Cloud - Serverless HDF
HDF for the Cloud - Serverless HDFHDF for the Cloud - Serverless HDF
HDF for the Cloud - Serverless HDF
 
HDF5 <-> Zarr
HDF5 <-> ZarrHDF5 <-> Zarr
HDF5 <-> Zarr
 
HDF for the Cloud - New HDF Server Features
HDF for the Cloud - New HDF Server FeaturesHDF for the Cloud - New HDF Server Features
HDF for the Cloud - New HDF Server Features
 
Apache Drill and Unidata THREDDS Data Server for NASA HDF-EOS on S3
Apache Drill and Unidata THREDDS Data Server for NASA HDF-EOS on S3Apache Drill and Unidata THREDDS Data Server for NASA HDF-EOS on S3
Apache Drill and Unidata THREDDS Data Server for NASA HDF-EOS on S3
 
STARE-PODS: A Versatile Data Store Leveraging the HDF Virtual Object Layer fo...
STARE-PODS: A Versatile Data Store Leveraging the HDF Virtual Object Layer fo...STARE-PODS: A Versatile Data Store Leveraging the HDF Virtual Object Layer fo...
STARE-PODS: A Versatile Data Store Leveraging the HDF Virtual Object Layer fo...
 
HDF5 and Ecosystem: What Is New?
HDF5 and Ecosystem: What Is New?HDF5 and Ecosystem: What Is New?
HDF5 and Ecosystem: What Is New?
 
HDF5 Roadmap 2019-2020
HDF5 Roadmap 2019-2020HDF5 Roadmap 2019-2020
HDF5 Roadmap 2019-2020
 

Dernier

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Dernier (20)

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

HDF-EOS Java Application Programming Interfaces

  • 1. HDF-EOS Java Application Programming Interfaces Genong (Eugene) Yu, Ph.D. Research associate Liping Di, Ph.D. Professor & Director of CSISS {gyu, ldi}@gmu.edu November 28-30, 2006 HDF and HDF-EOS Workshop X, Upper Marlboro, MD
  • 2. Outline • Why Java API interfaces? • Java API interfaces – Variable consideration • • • • Java Object wrap-up Performance consideration Applications Problem – Memory management
  • 3. Demand • Distribution systems over the Web – Java-based server • Apache Tomcat • Manipulation of data for the Web application – Re-projection service – Classification service – Re-format service
  • 4. Bridging Java Program and C/C++ library The Problem HDF-EOS HDF-EOS HDF-EOS HDF-EOS HDF-EOS HDF-EOS HDF JNI API • HDF-EOS library – in C/C++ library • All functions to manipulate grid and point are written in C • Primer for HDF-EOS is for C • HDF JNI libraries are available • Possible approach Java Reader • Rewrite the program in Java WEB APPLICATION • Pros: better for Java environment The Solution HDF-EOS HDF-EOS HDF-EOS HDF-EOS HDF-EOS HDF-EOS HDF-EOS / HDF JNI API Java Reader WEB APPLICATION • Cons: enormous work and need to keep track of revision • Call the library directly through JNI • Pros: manageable work and efficient re-use • Cons: memory management, debugging
  • 5. How JNI works (1) • Java interface – public static native int GDopen(String filename, int access) throws HDFEOSException; – Load library • System.loadLibrary("jhdfeos4"); • Compile the above code – javac HDFEOSLibrary.java • Create header File – javah -jni edu
  • 6. How JNI works (2) • Create the library in C/C++ – Template • JNIEXPORT void JNICALL Java_ClassName_MethodName (JNIEnv *env, jobject obj) { • //Implement Native Method Here • } – Example • JNIEXPORT jint JNICALL Java_edu_gmu_laits_hdfeos_HDFEOSLibrary_SWdupregion • (JNIEnv *env, jclass class, jint oldregionID) • { • int32 regionID; • regionID=SWdupregion((int32)oldregionID); • return (jint)regionID; • }
  • 7. Tasks to enable the JNI • To access a C library from a Java program, four tasks must be completed: – Declare appropriate “native” methods in Java classes – Write “interface” code for each native method to implement the JNI C or C++ standard – compile the JNI “interface” (C or C++) to create a JNI library – deploy the Java classes and the JNI library on the system
  • 8. Mapping types (1) • Interchangeable types Native type (C/C++) Java Language Description Type HDF/HDFEOS bool jboolean Unsigned 8 bits intn, uint8 byte jbyte Signed 8 bits int8 char jchar Unsigned 16 bits uint16 short jshort Signed 16 bits int16 long jint Signed 32 bits int32 long long jlong Signed 64 bits int64 Float jfloat Float 32 bits float32 Double jdouble Float 64 bits float64
  • 9. Mapping types (2) • String – Wrong • JNIEXPORT jint JNICALL Java_edu_gmu_laits_hdfeos_HDFEOSLibrary_SWcreate • (JNIEnv *env, jclass class, jint file_id, jstring swath_name) • { • return SWcreate( (int32)file_id, (char *) swath_name); • } – Correct • JNIEXPORT jint JNICALL Java_edu_gmu_laits_hdfeos_HDFEOSLibrary_SWcreate • (JNIEnv *env, jclass class, jint file_id, jstring swath_name) • { • char *s_filename; • int32 swath_id; • s_filename = (char *) (*env)->GetStringUTFChars( env, swath_name, 0); • swath_id = SWcreate( (int32)file_id, (char *)s_filename ); • (*env)->ReleaseStringUTFChars(env, swath_name, s_filename ); • return (jint)swath_id; • }
  • 10. Mapping types (3) • Array – – Wrong • JNIEXPORT jboolean JNICALL Java_edu_gmu_laits_hdfeos_HDFEOSLibrary_GDorigininfo • (JNIEnv *env, jclass class, jint gridID, jintArray origincode) • { • int32 status; • status= GDorigininfo((int32)gridID,(int32 *)origincode); • if (status==-1) return JNI_FALSE; • else return JNI_TRUE; • } Correct • • • • • • • • • • • JNIEXPORT jboolean JNICALL Java_edu_gmu_laits_hdfeos_HDFEOSLibrary_GDorigininfo (JNIEnv *env, jclass class, jint gridID, jintArray origincode) { int32 *i_origincode; int32 status; i_origincode=(int32 *)(*env)->GetIntArrayElements(env,origincode,0); status=GDorigininfo((int32)gridID,i_origincode); (*env)->ReleaseIntArrayElements(env,origincode,(jint *)i_origincode,0); if (status==-1) return JNI_FALSE; else return JNI_TRUE; }
  • 11. Mapping types (4) • Pointer – In C • intn SWattrinfo(int32 swathID, char *attrname, int32 * numbertype, int32 *count); – In Java • public static native boolean SWattrinfo(int swathID, String attrname, int[] numbertype, int[] count) throws HDFEOSException;
  • 12. The HDF-EOS library • Interface level – One class to hold all “native” methods – One C “interface” library – e.g. jhdfeos4 (dll, so) – One-to-one
  • 13. Hierarchy of objects dataset GeoDataset RasterDataset HESwathDataset HEGridDataset To be implemented HEGrid HEGridField HEGridFieldBand2d VectorDataset HEPointDataset To be implemented
  • 14. Thread safe vs. efficiency • Model 1: Access & close • Model 2: Open – access – close HEGridDataset HEGridDataset HEGrid HEGrid2 HEGridField HEGridField2 HEGridFieldBand2d HEGridFieldBand2d2 Model 1 Model 2
  • 15. Applications (1) • Web services – Conversion http://laits.gmu.edu:18080/DataMining/HDFEOS2ARFF?WSDL – Conversion http://laits.gmu.edu:18080/DataMining/ARFF2HDFEOS2?WSDL – Training http://laits.gmu.edu:18080/DataMining/LogisticRegressionTrainer ?WSDL – Classification http://laits.gmu.edu:18080/DataMining/LogisticRegressionClassif ier?WSDL – Regression http://laits.gmu.edu:18080/DataMining/LogisticRegressor?WSDL • Test pages http://laits.gmu.edu:18080/DataMiningClientWeb/
  • 17. Limitations to the JNI approach • Limitations – JNI is not an easy API; – Invocation: only applications and signed applets can invoke the JNI; – Portability: No • compile different set of libraries and dynamically load – Memory management: no garbage collection • Careful to manage memory and exception in C • Timely re-start Tomcat server (not a good solution) – Debugging difficulty: error checking is a MUST or it has the potential • to crash the server • to left dead thread • to cause memory leak
  • 18. Conclusions • The library is available at – http://laits.gmu.edu/~gyu/HDFEOS/
  • 19. Future work • Continue on updating the interface • Work on HDF5-EOS • Refine the object with considerations of performance and usability
  • 20. References • JNI specification http://java.sun.com/j2se/1.5.0/docs/guide/j ni/spec/jniTOC.html • Java Native Interface: Programmer’s Guide and Specification http://java.sun.com/docs/books/jni/
  • 21. Acknowledgements • The work was supported partially with grants from the NASA Earth Science Data and Information System Project (ESDISP) (NCC5-645, PI: Dr. Liping Di), NASA Earth Science Technology Office (ESTO) (NAG-13409, PI: Dr. Liping Di), NASA REASoN program (NNG04GE61A, PI: Dr. Liping Di), and National Geospatial-intelligence Agency (NGA) University Research Initiative (NURI) (HM1582-04-1-2021, PI: Dr. Liping Di). • Thanks to Dr. Peisheng Zhao, Dr. Aijun Chen, Dr. Yuqi Bai, Mr. Yaxing Wei, and other colleagues at Center for Spatial Information Science and System, George Mason University, for their inputs and contributions.