Advanced RbScript. by Thomas Tempelmann. Thomas Tempelmann RbScript 201

Similar documents
Lecture 20. Java Exceptional Event Handling. Dr. Martin O Connor CA166

CS2: Debugging in Java

Exceptions in Java

Deviations are things that modify a thread s normal flow of control. Unix has long had signals, and these must be dealt with in multithreaded

Advanced Language Features. by Christian Schmitz

Creating New Listen Only Caller Applications

238P Operating Systems, Fall Counting Semaphores. Discussed on whiteboard 30 November Slides Posted 10 December 2018

Signals. POSIX defines a variety of signal types, each for a particular

Shell Execution of Programs. Process Groups, Session and Signals 1

Interprocess Communication

Most of the work is done in the context of the process rather than handled separately by the kernel

STUDENT LESSON A9 Recursion

Supplement: Visual C++ Debugging

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

Dealing with Issues for Interprocess Communication

This is a talk given by me to the Northwest C++ Users Group on May 19, 2010.

CS0330 Gear Up: Database

Unix System Programming - Chapter 8

Le L c e t c ur u e e 5 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Exception Handling

Exploring UNIX: Session 5 (optional)

Reminder. Topics CSE What Are Exceptions?! Lecture 11 Exception Handling

What is the purpose of exceptions and exception handling? Vocabulary: throw/raise and catch/handle Exception propagation Java checked and unchecked

Operating Systems 2010/2011

Embedded Systems Programming

Towards Verifying Android Apps for the Absence of No-Sleep Energy Bugs

Debug for GDB Users. Action Description Debug GDB $debug <program> <args> >create <program> <args>

CS102 C++ Exception Handling & Namespaces

Signals. Joseph Cordina

9. Java Errors and Exceptions

void fun() C::C() // ctor try try try : member( ) catch (const E& e) { catch (const E& e) { catch (const E& e) {

Last class: Today: Thread Background. Thread Systems

Design Overview of the FreeBSD Kernel CIS 657

Design Overview of the FreeBSD Kernel. Organization of the Kernel. What Code is Machine Independent?

Processes and Threads

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras

10/17/ Gribble, Lazowska, Levy, Zahorjan 2. 10/17/ Gribble, Lazowska, Levy, Zahorjan 4

Exception Handling Introduction. Error-Prevention Tip 13.1 OBJECTIVES

Linux shell scripting Getting started *

Signals are a kernel-supported mechanism for reporting events to user code and forcing a response to them. There are actually two sorts of such

Note: in this document we use process and thread interchangeably.

Exceptions. Text: Chapter19, Big C++

Threading Support for Byebug

EECS 482 Introduction to Operating Systems

CS 3 Introduction to Software Engineering. 3: Exceptions

After completing this appendix, you will be able to:

Exception Handling. Chapter 11. Java By Abstraction Chapter 11. Outline What Are Exceptions?

EECS 482 Introduction to Operating Systems

COMP6771 Advanced C++ Programming

Online Activity: Debugging and Error Handling

Exception Handling Pearson Education, Inc. All rights reserved.

Introduction to Java. Handout-3a. cs402 - Spring

CSE : Python Programming. Homework 5 and Projects. Announcements. Course project: Overview. Course Project: Grading criteria

A read or write being atomic means that its effect is as if it happens instantaneously.

Menu Driven Systems. While loops, menus and the switch statement. Mairead Meagher Dr. Siobhán Drohan. Produced by:

Exception Handling. Chapter 11. Outline. Example: The Quotient app What Are Exceptions? Java By Abstraction Chapter 11

Oracle Service Bus. Interoperability with EJB Transport 10g Release 3 (10.3) October 2008

HPCC - Hrothgar. Getting Started User Guide TotalView. High Performance Computing Center Texas Tech University

St. MARTIN S ENGINEERING COLLEGE Dhulapally,Secunderabad DEPARTMENT OF INFORMATION TECHNOLOGY Academic year

Insights into WebSphere Process Server Tracing

Exceptions. Examples of code which shows the syntax and all that

Memory Management: High-Level Overview

I/O Systems. Jo, Heeseung

7 The Integrated Debugger

Concurrent and Real-Time Programming in Java

Administration. Exceptions. Leftovers. Agenda. When Things Go Wrong. Handling Errors. CS 99 Summer 2000 Michael Clarkson Lecture 11

ECE 391 Exam 1 Review Session - Spring Brought to you by HKN

Signals and Session Management. Signals. Mechanism to notify processes of system events

Systems Programming/ C and UNIX

An Introduction to Erlang

3. A Periodic Alarm: intdate.c & sigsend.c

BBM 102 Introduction to Programming II Spring Exceptions

Analysis of MS Multiple Excel Vulnerabilities

CSE 451: Operating Systems Winter Lecture 7 Synchronization. Steve Gribble. Synchronization. Threads cooperate in multithreaded programs

IS 0020 Program Design and Software Tools

Tech Note 256 Using Network Application Development (NAD) with InTouch

What is this? How do UVMs work?

Operating Systems. Synchronization

Lecture 9: Control Flow

CS330: Operating System and Lab. (Spring 2006) I/O Systems

The Kernel Abstraction

CIS192 Python Programming

G52CPP C++ Programming Lecture 16

CSE 153 Design of Operating Systems Fall 2018

Internationalization and Error Handling

Chapter 6: Process Synchronization

Using the Debugger. Michael Jantz Dr. Prasad Kulkarni

Constraint Satisfaction Problems: A Deeper Look

Programming Assignments will be.. All the PAs are continuous 3 major factors that you should consider

7. Java Input/Output. User Input/Console Output, File Input and Output (I/O)

Topic 16: Validation. CITS3403 Agile Web Development. Express, Angular and Node, Chapter 11

The Design and Implementation of syscalltrack

Run-Time Environments/Garbage Collection

Objectives for this class meeting. 1. Conduct review of core concepts concerning contracts and pre/post conditions

Orbix TS Thread Library Reference

1. Allowed you to see the value of one or more variables, or 2. Indicated where you were in the execution of a program

BBM 102 Introduction to Programming II Spring 2017

Exceptions. Exceptions. Can have multiple except suites and/or one unnamed except suite

Atropos User s manual

Orbix Release Notes

Debugging. John Lockman Texas Advanced Computing Center

Transcription:

Advanced RbScript by Thomas Tempelmann

Advanced RbScript Topics handled in this session First part Pausing a script that is waiting for an event using a semaphore Killing a thread that is suspended by a semaphore Catching exceptions in scripts Second part Exchanging object between the main program and its scripts

Pausing a script Situation: A script has to wait for input that it can not get immediately Examples: An event driven script that keeps running in a loop and waits for being told what to do A script may invoke an operation through a Context provided method that shall only return when an Event handler gets called (asynchronous network operations)

Pausing a script When the script makes a call to a Context-provided method, that method cannot return immediately because it must wait for the event to happen first. To achieve this, a Semaphore is used. It allows us to stop suspend execution of the method and instead have other program code run. Once the event we are waiting for occurs, we can release the semaphore to let the method continue

Pausing a script In order to use a semaphore, we have to run the script in a separate process (Thread).

RbScript example dim res as String do res = Input ("gimme a cookie") if res = "cookie" then print " yummy!" else print " bah!" end loop until res = "stop"

Code to invoke the script // prepare the semaphore ScriptLock = new Semaphore ScriptLock.Signal // run the script RbScript1.Run ()

Script s input processing // this gets called when the script calls the Input method: Function RbScript1.Input (prompt As String) As String ScriptLock.Signal return InputForScript End Function // this we call when we have input for the script: Sub ResumeScriptWithInput (inputmsg as String) InputForScript = inputmsg ScriptLock.Release End Sub

Killing a suspended thread Situation: The script s thread is still running (waiting) when its environment (window or application) is closing. This may lead to unexpected effects including raised exceptions. The Kill method of the Thread class does not work if the thread is locked by a semaphore, as it is in our case.

Killing a suspended thread The solution is to unlock the semaphore and have the freed code raise a ThreadEndException from inside the thread. The exception will have the effect that the script s loop is exited and eventually will end the script and return from the RbScript.Run() call in the thread. This in turn ends the thread properly.

Catching exceptions in scripts Situation: When an exception occurs in a script that is not getting caught, the documentation suggests that the script s RuntimeError event gets called with information about the exception, similar to the App s UnhandledException event, then the script ends and returns normally from the RbScript.Run() call. However, this is not happening.

Catching exceptions in scripts Situation (cont.): Instead, what happens is this: The RuntimeError event is not called The Run() method does not return normally but instead an exception is propagated. In some cases, the application may then crash. This is a confirmed bug and present in RB 5.5.5 as well as in 2006r1

Catching exceptions in scripts Solution (work-around): The script has to have a catch-all wrapper around its main code. Problem is that it must not use a variable to learn the type of the exception - that would cause another crash. This means that we can only learn that an exception has occurred, but not which type it is, nor get a stack trace. We use the Context to set a flag for reporting this incident to the Run() caller.

End of Part 1 The project EventDrivenScript.rbp contains a sample application using the aforementioned techniques.

Passing objects to the script Goals: We want to be able to let a script use objects in the same way we use them in our main program. In particular, the script shall have access to some of the same data we access in our main program.

Example of use in a script dim dir, f as FolderItem dim idx as Integer dir = DesktopFolder () for idx = 1 to dir.count () f = dir.trueitem (idx) Print f.name next

Passing objects to the script Key steps to the solution: We automatically add a set of classes to the user script that provide the classes and functions. Those added classes communicate with the main program through specially provided Context methods that the common part of the script does not officially know about.

Passing objects to the script Key steps to the solution (cont.): The added classes in the script create proxy instances of the main app s objects. To connect the app s objects to their script counterparts, Hash codes are used... These hash codes are Integer values that are unique to every existing object.

Passing objects to the script Key steps to the solution (cont.): When the script wants to create a proxy instance of a main app s object, it calls a context method, which finds the object and returns the object s hash value to the caller in the script. Later, if the script wants to access a property or member of such a proxy class, another context method is called along with the hash value for identification of the main app s obect.

Passing objects to the script Key steps to the solution (cont.): A Dictionary is used on the main app side to remember the objects the script proxy has requested. The proxy class implements the Destructor method from which it tells the main app (though another Context method) to release the object again, i.e. remove it from the Dictionary.

Passing objects to the script The project ScriptClassProxies.rbp contains a sample application using this technique. My thanks go to Joe Ranieri (aka. SirG3) for introducing me to this elegant way of using RbScript with complex data structures.

Demonstration Q & A