Copyright © 2012 Job and Esther Technologies, Inc.(2) CORE APIS ANDUTILITIES
Copyright © 2012 Job and Esther Technologies, Inc.Eqela core applicationframework (eq.api)
Copyright © 2012 Job and Esther Technologies, Inc.eq.api.ObjectBase class for all objects (generic)Automatically assumed a...
Copyright © 2012 Job and Esther Technologies, Inc.class MyClass{// class body}class MyClass : Object{// class body}class M...
Copyright © 2012 Job and Esther Technologies, Inc.public void process_object(Object o) {if(o is String) {; // Do string ac...
Copyright © 2012 Job and Esther Technologies, Inc.eq.api.PropertyObjectAbility to add arbitrary properties of various data...
Copyright © 2012 Job and Esther Technologies, Inc.var o = new PropertyObject();o.set("object", new Object());o.set_int("in...
Copyright © 2012 Job and Esther Technologies, Inc.eq.api.SignalObjectAbility to configure arbitrary signal/listener constr...
Copyright © 2012 Job and Esther Technologies, Inc.// Connecting to a signalvar so = new SignalObject();so.connect_signal("...
Copyright © 2012 Job and Esther Technologies, Inc.Dynamic object creationNormally classes are instantiated into objects w...
Copyright © 2012 Job and Esther Technologies, Inc.What is a primitive type?
Copyright © 2012 Job and Esther Technologies, Inc.Primitive types● Built in to the language as basic building blocks, andc...
Copyright © 2012 Job and Esther Technologies, Inc.Primitive objectsIn themselves, primitive types are NOT objectsPrimitive...
Copyright © 2012 Job and Esther Technologies, Inc.// To make objects out of primitive types.var p_double = Primitive.for_d...
Copyright © 2012 Job and Esther Technologies, Inc.In Eqela, strings are objects designed torepresent a sequence of charact...
Copyright © 2012 Job and Esther Technologies, Inc.String objectsA string in Eqela is an object instance of a class thatimp...
Copyright © 2012 Job and Esther Technologies, Inc.Constructing stringsvar strobject = "This is a string";var secondobject ...
Copyright © 2012 Job and Esther Technologies, Inc.Constructing stringsvar sb = StringBuffer.create();sb.append("This ");sb...
Copyright © 2012 Job and Esther Technologies, Inc.Formatting stringsAnother way to construct strings is through the use of...
Copyright © 2012 Job and Esther Technologies, Inc.var mystring = "This is %s. Very nice".printf().add("Hello").to_string()...
Copyright © 2012 Job and Esther Technologies, Inc.Memory allocation and buffers
Copyright © 2012 Job and Esther Technologies, Inc.eq.api.BufferEqela API supports arbitrary memory buffermanagement throu...
Copyright © 2012 Job and Esther Technologies, Inc.eq.api.DynamicBufferAllocating a chunk of memory can be done through th...
Copyright © 2012 Job and Esther Technologies, Inc.eq.api.PointerTo perform operations on a Buffer, use the Pointerinterfa...
Copyright © 2012 Job and Esther Technologies, Inc.Collections
Copyright © 2012 Job and Esther Technologies, Inc.Arrays and linked listsImplemented through types eq.api.Array andeq.api....
Copyright © 2012 Job and Esther Technologies, Inc.Collections: Examplesvar myarray = Array.create();var mylinkedlist = Lin...
Copyright © 2012 Job and Esther Technologies, Inc.Queues and StacksImplemented through eq.api.Queue and eq.api.StackBoth p...
Copyright © 2012 Job and Esther Technologies, Inc.What is a HashTable?
Copyright © 2012 Job and Esther Technologies, Inc.eq.api.HashTableAllows for creating collections of key-value pairsThe ke...
Copyright © 2012 Job and Esther Technologies, Inc.IteratorsThe framework provides a generic way to iterate overcollections...
Copyright © 2012 Job and Esther Technologies, Inc.Iterators: Examplevar ll = LinkedList.create();ll.add("first");ll.add("s...
Copyright © 2012 Job and Esther Technologies, Inc.Iterators: Example using foreachvar ll = LinkedList.create();ll.add("fir...
Copyright © 2012 Job and Esther Technologies, Inc.Logging and debugging (eq.api.Log)Provides message output and logging fa...
Copyright © 2012 Job and Esther Technologies, Inc.Accessing environment variablesEnvironment variables are a special facil...
Copyright © 2012 Job and Esther Technologies, Inc.var se = SystemEnvironment.instance();if(se != null) {se.set_env_var("EQ...
Copyright © 2012 Job and Esther Technologies, Inc.System clockGives access to the current time, as known by thesystem/devi...
Copyright © 2012 Job and Esther Technologies, Inc.TimersA "timer" is a way of scheduling code to execute at somelater time...
Copyright © 2012 Job and Esther Technologies, Inc.Timers: Example// start a timervar el = EventLoop.instance();if(el != nu...
Copyright © 2012 Job and Esther Technologies, Inc.Executing other programsEqela provides a mechanism to interact with othe...
Copyright © 2012 Job and Esther Technologies, Inc.Executing programs: Example// To execute other programs:var child = Chil...
Copyright © 2012 Job and Esther Technologies, Inc.Mathematics supporteq.api.MathProvides mathematical functions, methods...
Copyright © 2012 Job and Esther Technologies, Inc.Generic I/O framework
Copyright © 2012 Job and Esther Technologies, Inc.Generic I/O frameworkReaders and writersThe input / output framework i...
Copyright © 2012 Job and Esther Technologies, Inc.Generic I/O frameworkString readerCan be used to treat a string as a R...
Copyright © 2012 Job and Esther Technologies, Inc.Generic I/O frameworkBuffer readerTakes an arbitrary in-memory buffer,...
Copyright © 2012 Job and Esther Technologies, Inc.Generic I/O frameworkeq.api.InputStreamEnables buffered reading and co...
Copyright © 2012 Job and Esther Technologies, Inc.Generic I/O frameworkeq.api.OutputStreamSimilar to input stream, it ca...
Copyright © 2012 Job and Esther Technologies, Inc.Standard I/O streams
Copyright © 2012 Job and Esther Technologies, Inc.Standard I/O streamsEqela supports the concept of "stdin", "stdout" and...
Copyright © 2012 Job and Esther Technologies, Inc.Filesystem access
Copyright © 2012 Job and Esther Technologies, Inc.Filesystem accessThe Eqela file path notationEqela uses the "/" charac...
Copyright © 2012 Job and Esther Technologies, Inc.Filesystem accessExample:− On a Linux systemTo access the system C compi...
Copyright © 2012 Job and Esther Technologies, Inc.Filesystem accessThe File classThe normal way to access files in an Eq...
Copyright © 2012 Job and Esther Technologies, Inc. Eqela also supports flexibly configured file systems− (Virtual, networ...
Copyright © 2012 Job and Esther Technologies, Inc.Filesystem accessReading a fileAn "eq.api.Reader" object can be obtain...
Copyright © 2012 Job and Esther Technologies, Inc.Filesystem accessReading directory entriesAn application can iterate o...
Copyright © 2012 Job and Esther Technologies, Inc.PipesAllows an execution of an external program orcommand on the underl...
Copyright © 2012 Job and Esther Technologies, Inc.MultithreadingStarting a new threadImplemented through the eq.api.Thre...
Copyright © 2012 Job and Esther Technologies, Inc.A class that implements Runnable interface:To execute a new thread:class...
Copyright © 2012 Job and Esther Technologies, Inc.MultithreadingThread synchronization / lockingThis can be done through...
Copyright © 2012 Job and Esther Technologies, Inc.MultithreadingTask threadsAre special cases of multithreading, impleme...
Copyright © 2012 Job and Esther Technologies, Inc.class MyTask : Task{public Object run(EventReceiver listener) {if(listen...
Copyright © 2012 Job and Esther Technologies, Inc.Eqela utilities API (eq.util)
Copyright © 2012 Job and Esther Technologies, Inc. Writing an archive Implemented through eq.util.ArchiveWriter Creates...
Copyright © 2012 Job and Esther Technologies, Inc. add_directory()− Adds a directory to be written out to an archive. wr...
Copyright © 2012 Job and Esther Technologies, Inc. Reading and archive Implemented through eq.util.ArchiveReader Reads ...
Copyright © 2012 Job and Esther Technologies, Inc.Example:To construct an instance of an ArchiveReader:* archivename, of t...
Copyright © 2012 Job and Esther Technologies, Inc.XML ParserEqela provides a means of reading an XML file/string andgetti...
Copyright © 2012 Job and Esther Technologies, Inc.XML Parsereq.util.XMLKeyValueParser andeq.util.XMLHTTPResponseParser− B...
Copyright © 2012 Job and Esther Technologies, Inc.Encoding / decoding schemesURLURL encoding converts characters into a ...
Copyright © 2012 Job and Esther Technologies, Inc.Encoding / decoding schemesBase64Base64 is a group of similar encoding...
Copyright © 2012 Job and Esther Technologies, Inc.Encoding / decoding schemesExample:Text to encode:Using URL encoder:Usin...
Copyright © 2012 Job and Esther Technologies, Inc.CryptographyDefinitionCryptography is the art of protecting information...
Copyright © 2012 Job and Esther Technologies, Inc.CryptographyIn Eqela, cryptography is implemented through thefollowing ...
Copyright © 2012 Job and Esther Technologies, Inc.Cryptographyeq.util.BlockCipherFactoryContains two static methods:− cr...
Copyright © 2012 Job and Esther Technologies, Inc.Cryptographyeq.util.BlockCipherWriterTo construct a BlockCipherWriter ...
Copyright © 2012 Job and Esther Technologies, Inc.Cryptographyeq.util.BlockCipherReaderTo construct a BlockCipherReader ...
Copyright © 2012 Job and Esther Technologies, Inc.Process watchdogEqela API includes a utility for monitoring closedproce...
Copyright © 2012 Job and Esther Technologies, Inc.Process watchdog− start();This method starts watching/monitoring the ch...
Copyright © 2012 Job and Esther Technologies, Inc.Thank you
Eqela Core API and Utilities
Upcoming SlideShare
Loading in...5
×

Eqela Core API and Utilities

2,256

Published on

Published in: Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,256
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
1
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Eqela Core API and Utilities

  1. 1. Copyright © 2012 Job and Esther Technologies, Inc.(2) CORE APIS ANDUTILITIES
  2. 2. Copyright © 2012 Job and Esther Technologies, Inc.Eqela core applicationframework (eq.api)
  3. 3. Copyright © 2012 Job and Esther Technologies, Inc.eq.api.ObjectBase class for all objects (generic)Automatically assumed as the base classDeclared as “fundamental”Lightweight
  4. 4. Copyright © 2012 Job and Esther Technologies, Inc.class MyClass{// class body}class MyClass : Object{// class body}class MyClass : eq.api.Object{// class body}eq.api.Object: Examples
  5. 5. Copyright © 2012 Job and Esther Technologies, Inc.public void process_object(Object o) {if(o is String) {; // Do string actions}if(o is Buffer) {; // Do buffer actions}// etc.}Object as a generic type
  6. 6. Copyright © 2012 Job and Esther Technologies, Inc.eq.api.PropertyObjectAbility to add arbitrary properties of various datatypes to an objectAn object property is something that is identified by astring name, and with associated data in any datatypeCommon way of using is to inherit or by construction
  7. 7. Copyright © 2012 Job and Esther Technologies, Inc.var o = new PropertyObject();o.set("object", new Object());o.set_int("integerproperty", 100);o.set_bool("value_as_boolean", false);var obj = o.get("object");var intp = o.get_int("integerproperty", 55); // NOTE: Default valuevar b = o.get_bool("value_as_boolean");eq.api.PropertyObject: Examplesvar m = o.synchronize();// perform operations on shared dataif(m != null) {m..unlock();}
  8. 8. Copyright © 2012 Job and Esther Technologies, Inc.eq.api.SignalObjectAbility to configure arbitrary signal/listener constructs fora classSignals do not need to be explicitly declaredA signal with any name may be triggered at any time
  9. 9. Copyright © 2012 Job and Esther Technologies, Inc.// Connecting to a signalvar so = new SignalObject();so.connect_signal("customsignal", myhandler);// Triggering a signalso.trigger_signal("customsignal", “optional parameter”);// Declaring a signal handlerclass MyHandlerClass : SignalHandler {public Object on_signal(Object origin, String sigid, Object parameter) {Log.message("Got a signal");return(null);}}eq.api.SignalObject: ExamplesThe “myhandler” object could be an instance of the class MyHandlerClassimplementing "eq.api.SignalHandler", which must implement a single methodon_signal()
  10. 10. Copyright © 2012 Job and Esther Technologies, Inc.Dynamic object creationNormally classes are instantiated into objects with the newoperatorAlternative way to create objectsWith specific return typevar object = new ClassName();var object = ObjectFactory.create("custom.module.ClassName");var object = ObjectFactory.create("custom.module.ClassName") as SignalObject;
  11. 11. Copyright © 2012 Job and Esther Technologies, Inc.What is a primitive type?
  12. 12. Copyright © 2012 Job and Esther Technologies, Inc.Primitive types● Built in to the language as basic building blocks, andcannot be extended by the programmer. Passed byvalue in method calls.● strptr, ptr, void, double, bool, int, long, bytestrptr var_name = “abc”.to_strptr();ptr var_name = null;double var_name = 123.45;bool var_name = true;int var_name = 100000;long var_name = 100000;byte var_name = 100;void //refers to no data type at all
  13. 13. Copyright © 2012 Job and Esther Technologies, Inc.Primitive objectsIn themselves, primitive types are NOT objectsPrimitive types can be passed as an object by using thefollowing interfaces:eq.api.Integereq.api.Doubleeq.api.BooleanA class that implements all these interfaces iseq.api.Primitive
  14. 14. Copyright © 2012 Job and Esther Technologies, Inc.// To make objects out of primitive types.var p_double = Primitive.for_double(100.5);var p_int = Primitive.for_integer(100);var p_bool = Primitive.for_boolean(false);// Converting objects to primitive typesdouble val_double = ((Double)p_double).to_double();int val_int = ((Integer)p_int).to_integer();bool val_bool = ((Boolean)p_bool).to_boolean();Primitive objects: Examplespublic void my_method(Object obj) {var obj_double = obj as Double;if(obj_double != null) {var val_double = obj_double.to_double();}// same way for Integer and Boolean types}
  15. 15. Copyright © 2012 Job and Esther Technologies, Inc.In Eqela, strings are objects designed torepresent a sequence of charactersAn Eqela string object is immutable, therefore“modifying” a string creates a new object, and will notchange the originalStrings
  16. 16. Copyright © 2012 Job and Esther Technologies, Inc.String objectsA string in Eqela is an object instance of a class thatimplements the interface eq.api.StringA String object encapsulates the primitive type strptr, whichis rarely used outside of embedded programming languagecodeThe easiest way to create a string is to write:You can also directly call string methods:var strobject = "This is a string";var substring = "This is a string".substring(5, 2); // "is"
  17. 17. Copyright © 2012 Job and Esther Technologies, Inc.Constructing stringsvar strobject = "This is a string";var secondobject = strobject.append(" and this one");What are the values of the two objects below?
  18. 18. Copyright © 2012 Job and Esther Technologies, Inc.Constructing stringsvar sb = StringBuffer.create();sb.append("This ");sb.append("is ");sb.append_c(a);sb.append_c( );sb.append("string");var as_string = sb.to_string();A more efficient way to construct a string fromcomponents is to use eq.api.StringBuffer:
  19. 19. Copyright © 2012 Job and Esther Technologies, Inc.Formatting stringsAnother way to construct strings is through the use ofstring formattingThis can be done through the eq.api.StringFormatterinterface and the built-in printf() method of StringobjectsThe syntax is familiar to C programmers as being thesame as that of the classic C printf() function
  20. 20. Copyright © 2012 Job and Esther Technologies, Inc.var mystring = "This is %s. Very nice".printf().add("Hello").to_string();Formatting strings: Examplevar anotherstring = "Integer %d and double %f".printf().add(Primitive.for_integer(100)).add(Primitive.for_double(15.64)).to_string();What are the resulting strings in these cases?
  21. 21. Copyright © 2012 Job and Esther Technologies, Inc.Memory allocation and buffers
  22. 22. Copyright © 2012 Job and Esther Technologies, Inc.eq.api.BufferEqela API supports arbitrary memory buffermanagement through the Buffer interfaceeq.api.BufferAn instance of Buffer represents a chunk of memoryof a certain size, wherein the size is measured inbytes.A buffer instance has two main characteristics:− The size of the buffer in bytes− A pointer to the beginning of the buffer
  23. 23. Copyright © 2012 Job and Esther Technologies, Inc.eq.api.DynamicBufferAllocating a chunk of memory can be done through theuse the DynamicBuffer interfaceAn eq.api.DynamicBuffer is also an instance ofeq.api.Buffer (Buffer is a prerequisite of DynamicBuffer)Example: To allocate a buffer of 100 bytes:var mybuffer = DynamicBuffer.create(100);
  24. 24. Copyright © 2012 Job and Esther Technologies, Inc.eq.api.PointerTo perform operations on a Buffer, use the PointerinterfaceSupports the basic operations such as set_byte(), get_byte()and cpyfrom()Example:int n;var ptr = mybuffer.get_pointer();if(ptr != null) {for(n=0; n<mybuffer.get_size(); n++) {ptr.set_byte(n, n);}}
  25. 25. Copyright © 2012 Job and Esther Technologies, Inc.Collections
  26. 26. Copyright © 2012 Job and Esther Technologies, Inc.Arrays and linked listsImplemented through types eq.api.Array andeq.api.LinkedListBoth have eq.api.Collection as prerequisiteeq.api.Collection provides all commonly used featuresfor manipulating the data
  27. 27. Copyright © 2012 Job and Esther Technologies, Inc.Collections: Examplesvar myarray = Array.create();var mylinkedlist = LinkedList.create();public void addmethod(Collection c) {c.add("Hello");c.add("world");}addmethod(myarray);addmethod(mylinkedlist);The create() method is used to construct an instance of these types:You could define a method like this to add data:The addmethod() could be called like this:The add() method accepts the data type "eq.api.Object", thus any class thatderives from "eq.api.Object" can be added
  28. 28. Copyright © 2012 Job and Esther Technologies, Inc.Queues and StacksImplemented through eq.api.Queue and eq.api.StackBoth provide push(), pop() and peek() methods and canbe created using their static create() methodsThese classes do not implement the collection interfacelike arrays and linked lists
  29. 29. Copyright © 2012 Job and Esther Technologies, Inc.What is a HashTable?
  30. 30. Copyright © 2012 Job and Esther Technologies, Inc.eq.api.HashTableAllows for creating collections of key-value pairsThe key is a string, and the values can be quickly lookedup using the stringvar myhashtable = HashTable.create();myhashtable.set("key1", "First");myhashtable.set("key2", "Second");var ff = myhashtable.get("key2");The variable "ff" would contain a reference to the String object holdingthe value "Second"
  31. 31. Copyright © 2012 Job and Esther Technologies, Inc.IteratorsThe framework provides a generic way to iterate overcollections of dataThis functionality is used in many places throughout theframework, in eq.api.Collection, eq.api.LinkedList, etc.eq.api.Iterateable interface defines a single method iterate()that can be used to obtain an instance of eq.api.IteratorThe Iterator class has a single method next(), which returnsan eq.api.Object
  32. 32. Copyright © 2012 Job and Esther Technologies, Inc.Iterators: Examplevar ll = LinkedList.create();ll.add("first");ll.add("second");var it = ll.iterate();if(it != null) {Object o;while((o = it.next()) != null) {Log.message(o);}}This would print the two entries "first" and"second" on the output terminal
  33. 33. Copyright © 2012 Job and Esther Technologies, Inc.Iterators: Example using foreachvar ll = LinkedList.create();ll.add("first");ll.add("second");foreach(Object o in ll) {Log.message(o);}Functionally equivalent to the previous, but withmuch less code due to use of the foreachstructure
  34. 34. Copyright © 2012 Job and Esther Technologies, Inc.Logging and debugging (eq.api.Log)Provides message output and logging facilities in allsupported environmentsFour main methods:message()error()warning()debug()Log.message("This is my message");
  35. 35. Copyright © 2012 Job and Esther Technologies, Inc.Accessing environment variablesEnvironment variables are a special facility supported onmany platforms to relay variables from a parent process to achild processAccessed via eq.api.SystemEnvironmentMethods to interact with environment variables:get_env_vars()get_env_var()set_env_var()
  36. 36. Copyright © 2012 Job and Esther Technologies, Inc.var se = SystemEnvironment.instance();if(se != null) {se.set_env_var("EQ_DEBUG", "yes");var val = se.get_env_var("EQ_DEBUG");if(val != null && val.equals("yes")) {Log.message("it worked");}}Environment variables: Example
  37. 37. Copyright © 2012 Job and Esther Technologies, Inc.System clockGives access to the current time, as known by thesystem/device that the program is running onThe access is provided by eq.api.SystemClockMethods to retrieve current time:seconds()timeval()
  38. 38. Copyright © 2012 Job and Esther Technologies, Inc.TimersA "timer" is a way of scheduling code to execute at somelater timeThe Eqela API provides a facility to create any number oftimers through the "eq.api.EventLoop" type
  39. 39. Copyright © 2012 Job and Esther Technologies, Inc.Timers: Example// start a timervar el = EventLoop.instance();if(el != null) {var timer = el.start_timer(1000000, handler, null);}// An object of this class could be used as a handler:class MySampleHandler : Timer{public bool on_timer(Object arg) {Log.message("TIMER!");return(false);}}The object "handler" must be an instance of a class implementing"eq.api.Timer", which must implement a single method on_timer()
  40. 40. Copyright © 2012 Job and Esther Technologies, Inc.Executing other programsEqela provides a mechanism to interact with other programson the systemDepends on the platform where this is supportedImplemented through the following types:eq.api.ProcessManager (Enabling type)eq.api.ChildProcessCommand (Specifies the command,process and other parameters for executing the command)eq.api.ChildProcess (Represents a child process)
  41. 41. Copyright © 2012 Job and Esther Technologies, Inc.Executing programs: Example// To execute other programs:var child = ChildProcess.start(ChildProcessCommand.create().set_command("firefox"));int r = ChildProcess.execute(ChildProcessCommand.create().set_command("cat /proc/cpuinfo"));On most computer platforms, this would result in looking for this command inthe PATH, then executing itIt is also possible to execute a command, waitfor it to finish, and then return an integer-basedreturn value:
  42. 42. Copyright © 2012 Job and Esther Technologies, Inc.Mathematics supporteq.api.MathProvides mathematical functions, methods andoperations.To access the mathematical functions:* For a full reference of the functions, please refer to the Eqela API reference.eq.api.MathConstantProvides common mathematical constants.It does not need to be specifically created.var math = Math.instance();var sinpi = math.sin(MathConstant.M_PI);
  43. 43. Copyright © 2012 Job and Esther Technologies, Inc.Generic I/O framework
  44. 44. Copyright © 2012 Job and Esther Technologies, Inc.Generic I/O frameworkReaders and writersThe input / output framework in the Eqela API isfundamentally very much based on the concept ofreaders and writers.eq.api.Reader− read()eq.api.Writer− write()eq.api.ReaderWriter− Shortcut for a class that is both a Reader and a Writer.
  45. 45. Copyright © 2012 Job and Esther Technologies, Inc.Generic I/O frameworkString readerCan be used to treat a string as a Reader.Example:* This allows the string to be treated the same way as a file or network socket would.var rd = StringReader.create("This is my string");
  46. 46. Copyright © 2012 Job and Esther Technologies, Inc.Generic I/O frameworkBuffer readerTakes an arbitrary in-memory buffer, and treats it as aReader.* This allows the string to be treated the same way as a file or network socket would.Buffer writerTakes an arbitrary in-memory buffer, and treats it as aWriter* This allows the string to be treated the same way as a file or network socket would.var buf = DynamicBuffer.create(1000);var rd = BufferReader.create(buf);var buf = DynamicBuffer.create(1000);var wr = BufferWriter.create(buf);
  47. 47. Copyright © 2012 Job and Esther Technologies, Inc.Generic I/O frameworkeq.api.InputStreamEnables buffered reading and convenience methodsfor reading specific kinds of data.readline()− per-line reading of textnextbyte() and getbyte()− per-byte reading of textread_all_buffer() and read_all_string()− read the entire contents to either a buffer or a stringvar ins = InputStream.create(StringReader.create("my string to read"));var str = ins.read_all_string();
  48. 48. Copyright © 2012 Job and Esther Technologies, Inc.Generic I/O frameworkeq.api.OutputStreamSimilar to input stream, it can be used to print strings,lines, and/or buffers to a writer.It could be used as follows:* The string "Hello world" would be printed, along with a corresponding newlinecharacter, to the buffer.var buf = DynamicBuffer.create(1000);var os = OutputStream.create(BufferWriter.create(buf));os.println("Hello world");
  49. 49. Copyright © 2012 Job and Esther Technologies, Inc.Standard I/O streams
  50. 50. Copyright © 2012 Job and Esther Technologies, Inc.Standard I/O streamsEqela supports the concept of "stdin", "stdout" and"stderr".− popularized by C standard I/O library (stdio)eq.api.Stdineq.api.Stdouteq.api.StderrTo create streams:var stdin = Stdin.create(); // of type eq.api.Readervar stdout = Stdout.create(); // of type eq.api.Writervar stderr = Stderr.create(); // of type eq.api.WriterTo create readers and writers tosupply standard I/O streams wherethey are available
  51. 51. Copyright © 2012 Job and Esther Technologies, Inc.Filesystem access
  52. 52. Copyright © 2012 Job and Esther Technologies, Inc.Filesystem accessThe Eqela file path notationEqela uses the "/" character as a file name separator on allplatforms.The first component of the path name is special,and is interpreted by Eqela.Common FilePathsDescription/myRefers to the users home directory, or a Documents directory, or some otherplace that is reserved for the users files/appRefers to the directory where the application itself is installed, and where itsdata files are./tmp Refers to a directory where an application may write temporary files./native Refers to the filesystem of the underlying operating system.
  53. 53. Copyright © 2012 Job and Esther Technologies, Inc.Filesystem accessExample:− On a Linux systemTo access the system C compiler:/native/usr/bin/gcc− On Microsoft Windows:To access the commonly used “C:Program Files”:/native/c/Program Files
  54. 54. Copyright © 2012 Job and Esther Technologies, Inc.Filesystem accessThe File classThe normal way to access files in an Eqela application isvia the eq.api.File class.Two ways to construct a File object:1. Using an Eqela path:2. Using a platform native file path:* The path separator used for Windows system is “”.* Objects file1 and file2 refer to the same file.var file1 = File.for_eqela_path("/native/c/program files/testfile.txt");var file2 = File.for_native_path("C:Program Filestestfile.txt");
  55. 55. Copyright © 2012 Job and Esther Technologies, Inc. Eqela also supports flexibly configured file systems− (Virtual, network based, local or something else) The file system can be used in Eqela as long asthere is a class that implements theeq.api.FileSystem. To construct File objects pointing to files on aspecific filesystem, one can use the File.instance()method:var file = File.instance("/dir/file.txt", my_file_system);Filesystem access
  56. 56. Copyright © 2012 Job and Esther Technologies, Inc.Filesystem accessReading a fileAn "eq.api.Reader" object can be obtained for a fileusing the read() method:* This would read the contents of the file "text.txt" within the users files into the stringvariable "str"Writing a fileWriting a file can be done through either the write()method or the append():var ins = InputStream.create(File.for_eqela_path("/my/text.txt").read());var str = ins.read_all_string();var os = OutputStream.create(File.for_eqela_path("/my/hello.txt").write());os.println("Hello world");
  57. 57. Copyright © 2012 Job and Esther Technologies, Inc.Filesystem accessReading directory entriesAn application can iterate over files and directories in thefilesystem using the entries() method:foreach(File path in File.for_eqela_path("/my").entries()) {Log.message(path);}
  58. 58. Copyright © 2012 Job and Esther Technologies, Inc.PipesAllows an execution of an external program orcommand on the underlying system.eq.api.PipeTurns its output into an InputStream that can be read by theprogram.To create a Pipe InputStream:The piped command can be returned as a string throughthe use of the read() method:var pipe = Pipe.execute("ls /usr/bin");Log.message(Pipe.read_string("ls /usr/bin"));var buffer = Pipe.read_buffer("ls /usr/bin");
  59. 59. Copyright © 2012 Job and Esther Technologies, Inc.MultithreadingStarting a new threadImplemented through the eq.api.Thread andeq.api.Runnable classes.Usage:1. Call the static start() method in the“eq.api.Thread” class.2. Supply to it an instance of a class implementingthe "eq.api.Runnable" interface.
  60. 60. Copyright © 2012 Job and Esther Technologies, Inc.A class that implements Runnable interface:To execute a new thread:class MyRunnable : Runnable{public void run() {Log.message("In a new thread");}}Thread.start(new MyRunnable());Multithreading: Example
  61. 61. Copyright © 2012 Job and Esther Technologies, Inc.MultithreadingThread synchronization / lockingThis can be done through eq.api.Mutex type.− Mutex ensures that only one thread can access a sectionof code at any given time.− The section of code protected by a mutex is called a criticalsection.Establishing a mutex:var mutex = Mutex.create();mutex.lock();// ...// critical section code here// ...mutex.unlock();
  62. 62. Copyright © 2012 Job and Esther Technologies, Inc.MultithreadingTask threadsAre special cases of multithreading, implementedthrough eq.api.TaskThread.A task thread can handle a sequence of tasks and canqueue them to execute one after the other.Possible that this is not implemented on a givenplatform, returns null.Instead of a Runnable, a class must implement theeq.api.Task interface.
  63. 63. Copyright © 2012 Job and Esther Technologies, Inc.class MyTask : Task{public Object run(EventReceiver listener) {if(listener != null) {listener.on_event("Hello world");}return(null);}}class MyEventListener : EventListener{public void on_event(Object o) {Log.message(o);}}var tt = TaskThread.create();if(tt != null) {tt.schedule(new MyTask(), new MyEventListener());}The run() method of classMyTask will be executed first andthen the on_event() method ofclass MyEventListener.TaskThread: Example
  64. 64. Copyright © 2012 Job and Esther Technologies, Inc.Eqela utilities API (eq.util)
  65. 65. Copyright © 2012 Job and Esther Technologies, Inc. Writing an archive Implemented through eq.util.ArchiveWriter Creates an archive of files and/or directories to aformat unique only to Eqela. add()− Can add a file or a directory to to be written outto an archive. add_file()− Adds a file to be written out to an archive.Generic archive implementation
  66. 66. Copyright © 2012 Job and Esther Technologies, Inc. add_directory()− Adds a directory to be written out to an archive. write()− Writes an archive of files and/or directories that havebeen added.var aw = new ArchiveWriter();aw.add_file(myfile);aw.add_directory(mydirectory);aw.write(archivename);myfile, mydirectory and archivename are of type eq.api.File
  67. 67. Copyright © 2012 Job and Esther Technologies, Inc. Reading and archive Implemented through eq.util.ArchiveReader Reads only an archive file created by theArchiveWriter. You can also set/get the properties of an entry inthe archive through the following types:− eq.util.ArchiveReaderDirectoryEntry− eq.util.ArchiveReaderFileEntryGeneric archive implementation
  68. 68. Copyright © 2012 Job and Esther Technologies, Inc.Example:To construct an instance of an ArchiveReader:* archivename, of type eq.api.File, should be an archive created by ArchiveWriter. An archive can be extracted using the extract_to() method:* destdir, of type eq.api.File, is a destination directory where you would want thearchive to be extracted.var ar = ArchiveReader.for_file(archivename);// using the “ar” instance variable abovear.extract_to(destdir);
  69. 69. Copyright © 2012 Job and Esther Technologies, Inc.XML ParserEqela provides a means of reading an XML file/string andgetting its content through the following classes:eq.util.XMLParser− To construct an instance of this class:− The object to be parsed can come from:var xml = XMLParser.create();Source MethodFile parse_file()InputStream parse_input_stream()Reader parse_reader()String parse_string()
  70. 70. Copyright © 2012 Job and Esther Technologies, Inc.XML Parsereq.util.XMLKeyValueParser andeq.util.XMLHTTPResponseParser− Both classes contain a static method parse(),which returns an eq.api.HashTablevar xml = XMLKeyValueParser.parse(str);var xml = XMLHTTPResponseParser.parse(httpresponse);
  71. 71. Copyright © 2012 Job and Esther Technologies, Inc.Encoding / decoding schemesURLURL encoding converts characters into a formatthat can be transmitted over the Internet.Implemented through eq.util.URLEncodereq.util.URLDecoder− Contains static method encode() and decode()respectively.− Usage:var encoded_val = URLEncoder.encode(str);var decoded_val = URLDecoder.encode(str);
  72. 72. Copyright © 2012 Job and Esther Technologies, Inc.Encoding / decoding schemesBase64Base64 is a group of similar encoding schemes thatrepresent binary data in an ASCII string format bytranslating it into a radix-64 representation.Implemented through eq.util.Base64Encodereq.util.Base64Decoder− Contains static method encode() and decode()respectively.− Usage:var encoded_val = Base64Encoder.encode(str);var decoded_val = Base64Decoder.encode(str);
  73. 73. Copyright © 2012 Job and Esther Technologies, Inc.Encoding / decoding schemesExample:Text to encode:Using URL encoder:Using Base 64 encoder:EQ002: Eqela Application DevelopmentEQ002%3A+Eqela+Application+DevelopmentRVEwMDI6IEVxZWxhIEFwcGxpY2F0aW9uIERldmVsb3BtZW50
  74. 74. Copyright © 2012 Job and Esther Technologies, Inc.CryptographyDefinitionCryptography is the art of protecting information (plaintext)by transforming it (encryption) into unreadable format(ciphertext).Decryption is moving from ciphertext back to plaintext.A block cipher is a pair of deterministic algorithm(encryption and decryption) operating on fixed-length groupsof bits.The detailed operation of a cipher is controlled both by thealgorithm and in each instance by a key (secret parameter).Source: http://en.wikipedia.org/wiki/Block_cipher#Definitionhttp://en.wikipedia.org/wiki/Cryptography
  75. 75. Copyright © 2012 Job and Esther Technologies, Inc.CryptographyIn Eqela, cryptography is implemented through thefollowing classes:eq.util.BlockCipherFactoryeq.util.DummyBlockCiphereq.api.BlockCiphereq.api.BlockCipherWritereq.api.BlockCipherReader
  76. 76. Copyright © 2012 Job and Esther Technologies, Inc.Cryptographyeq.util.BlockCipherFactoryContains two static methods:− create(name, key)− get_ciphers()var ciphers = BlockCipherFactory.get_ciphers();var bc = BlockCipherFactory.create(name, key);The variable “ciphers” holds a collection of supported block ciphers returned bythe get_cipher() methodThe variable name could have a string value “dummy”, in which case thecreate() method will return an eq.util.DummyBlockCipher object. Or, it could alsohave other values of block cipher methods, such as “aes-128”, which will thenreturn an eq.util.BlockCipher type.
  77. 77. Copyright © 2012 Job and Esther Technologies, Inc.Cryptographyeq.util.BlockCipherWriterTo construct a BlockCipherWriter object:Example:Input Plaintext: Hello WorldOutput Ciphertext: Œ÷(j~~ü§r˜1&žvar bcw = BlockCipherWriter.create(writer, cipher);String name = "aes-128";String key = “password”;var bc = BlockCipherFactory.create(name, key);var bcw = BlockCipherWriter.create(File.for_eqela_path("testfile.txt").write(), bc);bcw.write(“Hello World”.to_utf8_buffer());
  78. 78. Copyright © 2012 Job and Esther Technologies, Inc.Cryptographyeq.util.BlockCipherReaderTo construct a BlockCipherReader object:Example:Input Ciphertext: Œ÷(j~~ü§r˜1&žOutput Plaintext: Hello Worldvar bcr = BlockCipherReader.create(Reader, cipher);String name = "aes-128";String key = “password”;var bc = BlockCipherFactory.create(name, key);var bcr = BlockCipherReader.create(File.for_eqela_path("testfile.txt").read(), bc);var ins = InputStream.create(bcr);Log.message(ins.read_all_string());
  79. 79. Copyright © 2012 Job and Esther Technologies, Inc.Process watchdogEqela API includes a utility for monitoring closedprocesses.Implemented through eq.util.ProcessWatchDogIntended to start a process, and then "watch it". If thechild process dies or exits, then the watchdog restartsitContains the following methods:− add(cmd, aname);This method adds a child process to the “watch list” andthen starts it.
  80. 80. Copyright © 2012 Job and Esther Technologies, Inc.Process watchdog− start();This method starts watching/monitoring the childprocesses that are in the “watch list”.− stop();Stops all child processes.− remove(name);Removes a child process from the “watch list”.
  81. 81. Copyright © 2012 Job and Esther Technologies, Inc.Thank you

×