Java and JCA. Rok Sabjan 09/01/2008. Based on presentation by Ken Evans. www.cosylab.com

Similar documents
Channel Access Client Programming. Andrew Johnson Computer Scientist, AES-SSG

3.5. cmsg Developer s Guide. Data Acquisition Group JEFFERSON LAB. Version

An Overview of Java. overview-1

Programming Languages

Creating a Simple, Multithreaded Chat System with Java

CSC230 Getting Starting in C. Tyler Bletsch

Tutorial 5: Developing Java applications

INTRODUCTION TO JAVA PROGRAMMING LANGUAGE

LAB 1. Familiarization of Rational Rose Environment And UML for small Java Application Development

1.00 Lecture 1. Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders

Development of Java ME

Accessing PostgreSQL through JDBC via a Java SSL tunnel

SE 450 Object-Oriented Software Development. Requirements. Topics. Textbooks. Prerequisite: CSC 416

Crash Course in Java

How To Run A Test File Extension On A Rexx (Unix) On A Microsoft Linux (Amd64) (Orchestra) (For Windows) (

CA SiteMinder. Programming Guide for Java. r12.0 SP2

CS506 Web Design and Development Solved Online Quiz No. 01

What Perl Programmers Should Know About Java

Logging in Java Applications

The BSN Hardware and Software Platform: Enabling Easy Development of Body Sensor Network Applications

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Building Applications Using Micro Focus COBOL

Getting Started with the Internet Communications Engine

The Java Virtual Machine and Mobile Devices. John Buford, Ph.D. Oct 2003 Presented to Gordon College CS 311

NetFlow Collection and Processing Cartridge Pack User Guide Release 6.0

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Admin. Mobile Software Development Framework: Android Activity, View/ViewGroup, External Resources. Recap: TinyOS. Recap: J2ME Framework

CSC 551: Web Programming. Spring 2004

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

Demo: Controlling.NET Windows Forms from a Java Application. Version 7.3

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

DIPLOMADO DE JAVA - OCA

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

IMPLEMENTATION OF AN AGENT MONITORING SYSTEM IN A JINI ENVIRONMENT WITH RESTRICTED USER ACCESS

Java Crash Course Part I

Manual. Programmer's Guide for Java API

Reach 4 million Unity developers

Applets, RMI, JDBC Exam Review

Learning Outcomes. Networking. Sockets. TCP/IP Networks. Hostnames and DNS TCP/IP

Using the VMRC Plug-In: Startup, Invoking Methods, and Shutdown on page 4

Java 7 Recipes. Freddy Guime. vk» (,\['«** g!p#« Carl Dea. Josh Juneau. John O'Conner

Sample copy. Introduction To WebLogic Server Property of Web 10.3 Age Solutions Inc.

Configuring the LCDS Load Test Tool

Contents. Java - An Introduction. Java Milestones. Java and its Evolution

Mobile application development J2ME U N I T I I

An Incomplete C++ Primer. University of Wyoming MA 5310


Java SE 7 Programming

Java SE 7 Programming

AP Computer Science Java Subset

Java Interview Questions and Answers

Using Actian PSQL as a Data Store with VMware vfabric SQLFire. Actian PSQL White Paper May 2013

Installing (1.8.7) 9/2/ Installing jgrasp

How to Install Java onto your system

Quartz.Net Scheduler in Depth

Java CPD (I) Frans Coenen Department of Computer Science

Android Fundamentals 1

How To Write A Program In Java (Programming) On A Microsoft Macbook Or Ipad (For Pc) Or Ipa (For Mac) (For Microsoft) (Programmer) (Or Mac) Or Macbook (For

Java SE 7 Programming

JAVA DEVELOPER S GUIDE TO ASPRISE SCANNING & IMAGE CAPTURE SDK

System Structures. Services Interface Structure

Tutorial on OpenCV for Android Setup

Mobile Application Languages XML, Java, J2ME and JavaCard Lesson 04 Java

CA SiteMinder Web Services Security

LICENSE4J FLOATING LICENSE SERVER USER GUIDE

CS 209 Programming in Java #1

ORACLE GOLDENGATE BIG DATA ADAPTER FOR HIVE

CSE 452: Programming Languages. Acknowledgements. Contents. Java and its Evolution

Specialized Android APP Development Program with Java (SAADPJ) Duration 2 months

Android Basics. Xin Yang

Virtuozzo Virtualization SDK

eggon SDK for ios 7 Integration Instructions

Multithreading and Java Native Interface (JNI)!

VOC Documentation. Release 0.1. Russell Keith-Magee

With a single download, the ADT Bundle includes everything you need to begin developing apps:

Installing Java. Table of contents

CS 111 Classes I 1. Software Organization View to this point:

Numerical Algorithms Group

Tutorial: Getting Started

SETTING UP YOUR JAVA DEVELOPER ENVIRONMENT

EJB 3.0 and IIOP.NET. Table of contents. Stefan Jäger / stefanjaeger@bluewin.ch

Fundamentals of Java Programming

Using jvmstat and visualgc to Solve Memory Management Problems

Java is commonly used for deploying applications across a network. Compiled Java code

Introduction to Android

Mocean Android SDK Developer Guide

Java on z/os. Agenda. Java runtime environments on z/os. Java SDK 5 and 6. Java System Resource Integration. Java Backend Integration

A generic framework for game development

JAVA Program For Processing SMS Messages

Instrumentation for Linux Event Log Analysis

IBM SDK, Java Technology Edition Version 1. IBM JVM messages IBM

The Java Logging API and Lumberjack

Manage and Monitor your JVM with JMX

AdFalcon Android SDK Developer's Guide. AdFalcon Mobile Ad Network Product of Noqoush Mobile Media Group

PubMatic Android SDK. Developer Guide. For Android SDK Version 4.3.5

Example of Standard API

Java and IRC. What Is IRC? Nicks, Channels and Operators. Using IRC. What Is an IRC Bot? IRC Protocol

Characteristics of Java (Optional) Y. Daniel Liang Supplement for Introduction to Java Programming

OPERATING SYSTEM SERVICES

Transcription:

Java and JCA Rok Sabjan 09/01/2008 Based on presentation by Ken Evans www.cosylab.com

Outline Java Java and EPICS Overview of JCA Examples - SimpleJCAGet - SimpleJCAMonitor - JProbe 2

Java Java is designed to be platform independent - Write once, run everywhere Java programs are interpreted by another program, possibly on another machine - The Java Virtual Machine (Java VM) Java technology includes - J2SE Standard Edition - J2EE Enterprise Edition (Multi-tier business apps) - J2ME Micro Edition (Phones, PDAs, etc.) Java is advertised to be all of these Simple Architecture neutral Object oriented Portable Distributed High performance Interpreted Multithreaded Robust Dynamic Secure 3

Java and EPICS EPICS Channel Access is native code - Not platform independent - Build cycle is edit compile [to machine code] - link - run Pure Java - Build cycle is edit compile [to byte code] run [anywhere] Java Native Interface [JNI] is used to access native code - Not Pure Java - No longer platform independent - You generate shared object or DLL libraries that must be used with the Java program You can write your own JNI - Not that hard if you know Channel Access The EPICS build system handles Java projects and JNI Ant is an alternative 4

JCA Stands for Java Channel Access JCA is a JNI implementation of an EPICS Channel Access client library for Java - Provides equivalents to most of the Channel Access API - Developed by Eric Boucher while at the APS - Currently taken over by Cosylab Available for download at - http://www.cosylab.com/jca Latest version is 2.1.3 at Cosylab JCA Version 1 uses EPICS Base 3.13 JCA Version 2 uses EPICS Base 3.14 - Channel Access is threaded - Allows for preemptive callbacks Works better with Java, which is inherently threaded 5

CAJ CAJ is a Java replacement for Channel Access Under development at Cosylab (Control Systems Laboratory) - http://www.cosylab.com - Located in Ljubljana in Slovenia - Situated between Austria (North), Italy (West), Hungary (East) and Croatia (South) - Cosylab also develops VDCT Will allow your programs to be Pure Java Can be used with JCA - Replaces JNI implementation - Requires replacing only one line of code jca.createcontext(jcalibrary.jni_thread_safe); jca.createcontext( com.cosylab.epics.caj.cajcontext ); 6

Requirements Java J2SE installed (Current [suggested] version is 1.4.2) JCA - Java libraries Download source and/or JAR files from the web - Native JNI libraries Download from the web or build them Currently found with the 2.1.2 distribution only jca.dll Windows libjca.so Unix (Currently only Linux) Your project - JCA files need to be in your CLASSPATH - UNIX: Shared object library needs to be in your LD_LIBRARY_PATH - Windows: DLL needs to be in your PATH 7

Resources EPICS web pages - http://www.aps.anl.gov/epics/index.php - Look under Extensions, then JCA JCA 2.1.2 API - http://www.aps.anl.gov/xfd/softdist/swbcda/jca/2.1.2/api/index.htm JCA 2.1.3 API - http://www.cosylab.com/jca/apidocs/index.html Java Tutorial - http://java.sun.com/learning/tutorial/index.html J2SE Documentation - http://java.sun.com/reference/api/index.html J2SE 1.4.2 API (Javadoc) - http://java.sun.com/j2se/1.4.2/docs/api/overview-summary.html 8

JCA Packages Five Packages - gov.aps.jca Channel-Access-like routines - gov.aps.jca.configuration Configuration - gov.aps.jca.dbr DBR types - gov.aps.jca.event Event handling - gov.aps.jca.jni Native interface functions 9

gov.aps.jca This is the package you will use most directly Classes - CASeverity Enum - CAStatus JCALibrary - Channel Monitor - Channel.ConnectionState ValuedEnum - Context Exceptions - CAException TimeoutException 10

JCALibrary Initializes JCA JCALibrary jca=jcalibrary.getinstance(); There is only one instance Used to create contexts and manage JCA configuration info Properties - JNI_THREAD_SAFE preemptive Suggested for Java, which is inherently threaded - JNI_SINGLE_THREADED non-preemptive Methods - createcontext - getproperty - listproperties - getversion, getrevision, getmodification 11

Context Corresponds to a Channel Access context Created by JCALibrary.createContext createcontext(jcalibrary.jni_single_threaded) createcontext(jcalibrary.jni_thread_safe) Controls all IO You can have more than one context Methods - createchannel - flushio, pendio, pendevent, poll - attachcurrentthread - addcontextexceptionlistener, removecontextexceptionlistener - addcontextmessagelistener, removecontextmessagelistener - destroy 12

Channel Represents a Channel Access channel Created by Context.createChannel createchannel(string name, connectionlistener l) Properties - CLOSED CONNECTED - DISCONNECTED NEVER_CONNECTED Methods - get, many overloads - put, many overloads - getname, getconnectionstate, getelementcount, etc. - addmonitor - addconnectionlistener, removeconnectionlistener - addaccessrightslistener, removeaccessrightslistener - destroy 13

Monitor Represents a Channel Access monitor Created by Channel.addMonitor addmonitor(dbrtype type, int count, int mask, MonitorListener l) Properties - ALARM LOG VALUE Methods - addmonitorlistener, removemonitorlistener - getmonitorlistener, getmonitorlisteners - clear - getchannel, getcontext - getcount, getmask, gettype - ismonitoringalarm, ismonitoringlog, ismonitoringvalue 14

MonitorListener Part of gov.aps.jca.event One method - monitorchanged Example { private class MyMonitorListener implements MonitorListener public void monitorchanged(monitorevent ev) { } // Call my handler onvaluechanged(ev); }; The value and status comes with the MonitorEvent 15

MonitorEvent Part of gov.aps.jca.event Methods - getdbr How you get the value - getstatus How you determine the status Example if(ev.getstatus() == CAStatus.NORMAL) { } DBR dbr=ev.getdbr(); double [] value=((double)dbr).getdoublevalue(); 16

Event Types MonitorListener GetListener PutListener AccessRightsListener ConnectionListener MonitorEvent GetEvent PutEvent AccessRightsEvent Connection Event ContextExceptionListener ContextExceptionEvent ContextMessageListener ContextMessageEvent Events all inherit from CAEvent They all work similarly to Monitor - Call the routine that fires the event when it occurs - Add a listener with the appropriate handler - Get the data from the event that is passed to your handler 17

gov.aps.jca.dbr Implements the EPICS DBR_xxx types Interfaces - DOUBLE, FLOAT, INT, STRING, TIME, CTRL, etc. Primary Class - DBR Subclasses of DBR - DBR_Double, DBR_Float, DBR_Int, DBR_STS_Double, etc. Example: DBR_STS_Double - Interfaces STS, DOUBLE - Extends DBR_Double - Subclasses DBR_GR_Double, DBR_Time_Double 18

SimpleJCAGet package simplejca; import gov.aps.jca.*; import gov.aps.jca.dbr.*; 19

SimpleJCAGet public class SimpleJCAGet { public static void main(string[] args) { SimpleJCAGet simplejcaget = new SimpleJCAGet(); JCALibrary jca=null; Context ctxt=null; Channel chan=null; // Parse the command line if(!simplejcaget.parsecommand(args)) System.exit(1); if(!simplejcaget.pvspecified) { System.err.println("No PV specified\n"); System.exit(1); } 20

SimpleJCAGet // Initialize and search try { // Get the JCALibrary instance jca=jcalibrary.getinstance(); // Create a non-preemptive context context=jca.createcontext( JCALibrary.JNI_SINGLE_THREADED); // Search chan=ctxt.createchannel(simplejcaget.name); // Wait for search ctxt.pendio(simplejcaget.timeout); } catch(exception ex) { System.err.println("Search failed for " + simplejcaget.name + ":\n" + ex); System.exit(1); } 21

SimpleJCAGet // Get the first value as a String try { // Get the value String [] value; value=((string)chan.get(dbrtype.string,1)). getstringvalue(); // Wait for the get ctxt.pendio(simplejcaget.timeout); // Print the value System.out.println("The value of " + simplejcaget.name + " is " + value[0]); } catch(exception ex) { System.err.println("Get failed for " + simplejcaget.name + ":\n" + ex); System.exit(1); } 22

SimpleJCAGet // Clean up try { // Clear the channel chan.destroy(); // Destroy the context ctxt.destroy(); } catch(exception ex) { System.err.println("Clean up failed for " + simplejcaget.name + ":\n" + ex); System.exit(1); } // Successful exit System.exit(0); } 23

SimpleJCAGet output java.exe -classpath <simplejca-path>\simplejca.jar; <jca-path>\jca-2.1.3.jar simplejca.simplejcaget evans:calc The value of evans:calc is 3 24

SimpleJCAMonitor Similar to SimpleJCAGet - Imports, parsing the command line, etc. are the same We will have listeners We will use JNI_THREAD_SAFE (preemptive) We will use flushio and not pendio, etc. 25

SimpleJCAMonitor /** Implementation of Connection Listener class */ private class SJCAConnectionListener implements ConnectionListener { public void connectionchanged(connectionevent ev) { onconnectionchanged(ev); } }; /** Implementation of MonitorListener class */ private class SJCAMonitorListener implements MonitorListener { public void monitorchanged(monitorevent ev) { onvaluechanged(ev); } }; 26

SimpleJCAMonitor // Instance of SimpleJCAMonitor SimpleJCAMonitor sjcam=new SimpleJCAMonitor(); // Initialize JCA try { // Get the JCALibrary instance jca=jcalibrary.getinstance(); // Create a preemptive context, default configuration ctxt=jca.createcontext(jcalibrary.jni_thread_safe); } catch(exception ex) { System.err.println("Initialization failed for " + sjcam.name + ":\n" + ex); System.exit(1); } 27

SimpleJCAMonitor // Search try { // Search chan=ctxt.createchannel(sjcam.name, sjcam.new SJCAConnectionListener()); ctxt.flushio(); } catch(exception ex) { System.err.println("Search failed for " + sjcam.name + ":\n" + ex); System.exit(1); } 28

SimpleJCAMonitor private void onconnectionchanged(connectionevent ev) { Channel ch=(channel)ev.getsource(); Context ctxt=ch.getcontext(); // Start a monitor on the first connection if(connectioncounter == 0 && ch.getconnectionstate() == Channel.CONNECTED) { try { // Add a monitor listener and flush ch.addmonitor(dbrtype.string,1, Monitor.VALUE Monitor.LOG Monitor.ALARM, new SJCAMonitorListener()); ctxt.flushio(); } catch(exception ex) { ex.printstacktrace(); } } 29

SimpleJCAMonitor // Print connection state if(ch.getconnectionstate() == Channel.CONNECTED) { System.out.println(ch.getName() + " is connected"); } else if(ch.getconnectionstate() == Channel.CLOSED) { System.out.println(ch.getName() + " is closed"); } else if(ch.getconnectionstate() == Channel.DISCONNECTED) { System.out.println(ch.getName() + " is disconnected"); } else if(ch.getconnectionstate() == Channel.NEVER_CONNECTED) { System.out.println(ch.getName() + " is never connected"); } 30

SimpleJCAMonitor private void onvaluechanged(monitorevent ev) { Channel ch=(channel)ev.getsource(); Context ctxt=ch.getcontext(); // Check the status if (ev.getstatus()!= CAStatus.NORMAL) { System.err.println("monitorChanged: Bad status ); } // Get the value from the DBR try { DBR dbr=ev.getdbr(); String [] value=((string)dbr).getstringvalue(); } System.out.print(SJCAUtils.timeStamp() + " " + getname() + ": + value[0]); } catch(exception ex) {... } 31

Simple JCAMonitor output Oct 11, 2004 10:36:43.661 Starting Simple JCA Monitor Oct 11, 2004 10:36:44.083 Search successful for: evans:calc CHANNEL : evans:calc TYPE : gov.aps.jca.dbr.dbrtype[dbr_double=6] COUNT : 1 STATE : gov.aps.jca.channel $ConnectionState[CONNECTED=2] HOSTNAME : ctlapps4l188.aps4.anl.gov:5064 READ : true WRITE : true Oct 11, 2004 10:36:44.208 evans:calc is connected Oct 11, 2004 10:36:44.224 evans:calc: 2 Oct 11, 2004 10:36:44.224 evans:calc: 3... Oct 11, 2004 10:36:53.240 evans:calc: 3 Oct 11, 2004 10:36:53.740 evans:calc: 4 Oct 11, 2004 10:36:54.036 All Done 32

JProbe JProbe is a simple example that demonstrates using JCA in a Swing GUI 33

Write once, run everywhere? 34

Source files for Simple JCA routines All the source and JAR files should be available with the presentation - LICENSE - SimpleJCA.jar - simplejca SimpleJCAMonitor.java SimpleJCAGet.java SJCAUtils.java - JProbe.jar - jprobe JProbe.java MainFrame.java AboutBoxPanel.java Stored as SimpleJCA.zip 35

Acknowledgements JCA was developed by Eric Boucher while at the APS Matej Sekoranja [Cosylab] has taken over JCA and is developing CAJ Both of these people were very helpful in getting JCA working for me 36

Thank You This has been an APS Controls Presentation 37

Thank You This has been an APS Controls Presentation 38