1 / 26

Software Engineering

Software Engineering. Recitation 7 Suhit Gupta. Review. Anything from last time???. Today. Threads/pthreads Bit operators in Java The GNU make utility Javadocs RMI/Siena. Threads/pThreads. We have already done threads (therefore we are going to skip)

iren
Télécharger la présentation

Software Engineering

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Software Engineering Recitation 7 Suhit Gupta

  2. Review • Anything from last time???

  3. Today • Threads/pthreads • Bit operators in Java • The GNU make utility • Javadocs • RMI/Siena

  4. Threads/pThreads • We have already done threads (therefore we are going to skip) • pThreads used in C. (POSIX Threads) • pThreads is the name of a machine-independent library of functions that are generally used to facilitate the multiprocessing of programs on shared memory machines. • pThreads is used to synchronize threads.

  5. Bit Operators • Bit operators treat Number types as a 32 bit value, change bits according to the operator and then converts the value back to Number when done. The operators are bitwise NOT (~), AND (&), OR (|), XOR (^), left shift (<<), right shift (>>), unsigned right shift (>>>).

  6. Bit operators in Java • Bitwise operations are not to be confused with logical operations (&&, ||...) • & - and • | - or • << - shift left • >> - shift right • ^ - XOR • ~ - compliment/not

  7. Bitwise operators • Bitwise operators (AND, OR) can be used in place of logical operators (&&,||), but they are less efficient, because logical operators are designed to reduce the number of comparisons made, in an expression, to the optimum: as soon as the truth or falsity of an expression is known, a logical comparison operator quits. A bitwise operator would continue operating to the last before the final result were known. • Bitwise operators are basically arithmetic operation. • Now, bitwise are not really inefficient because they are truly put on the chip… • The first point is more or less in C. In Java they are fairly different operations.

  8. Eg- 128 64 32 16 8 4 2 1 ----------------------------------- | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | = 1 ----------------------------------- • Shift operators move whole bit patterns left or right by shunting them between boxes. The syntax of this operation is: • 1 << 1 would have the value 2, because the bit pattern would have been moved one place the the left: 128 64 32 16 8 4 2 1 ----------------------------------- | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | = 2 ----------------------------------- • Similarly: 1 << 4 has the value 16 because the original bit pattern is moved by four places: 128 64 32 16 8 4 2 1 ----------------------------------- | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | = 16 ----------------------------------- • And: 6 << 2 == 12 128 64 32 16 8 4 2 1 ----------------------------------- | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | = 6 ----------------------------------- • Shift left 2 places: 128 64 32 16 8 4 2 1 ----------------------------------- | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | = 12 -----------------------------------

  9. The GNU make utility • http://www.gnu.org/manual/make-3.79.1/html_node/make_toc.html • The make utility automatically determines which pieces of a large program need to be recompiled, and issues commands to recompile them. • You have to have a Makefile • Run make to start rules in the Makefile file.

  10. Example of a Makefile edit : main.o kbd.o command.o display.o \ insert.o search.o files.o utils.o cc -o edit main.o kbd.o command.o display.o \ insert.o search.o files.o utils.o main.o : main.c defs.h cc -c main.c kbd.o : kbd.c defs.h command.h cc -c kbd.c command.o : command.c defs.h command.h cc -c command.c display.o : display.c defs.h buffer.h cc -c display.c insert.o : insert.c defs.h buffer.h cc -c insert.c search.o : search.c defs.h buffer.h cc -c search.c files.o : files.c defs.h buffer.h command.h cc -c files.c utils.o : utils.c defs.h cc -c utils.c clean : rm edit main.o kbd.o command.o display.o \ insert.o search.o files.o utils.o

  11. From the example • To use this makefile to create the executable file called ‘edit’, type: make • make clean

  12. Javadocs • http://java.sun.com • Javadoc provides a way to integrate code comments with program documentation. • Enter comments with a series of flags to indicate the type of comment/documentation • Run javadoc to parse the flags and the comments to create an html file documentation of the code

  13. Example If you miss recitation then you will miss the demonstration You can run – javadoc somefile.java

  14. RMI/Siena • We have done Siena (therefore we will skip) • Remote Method Invocation (RMI) enables the programmer to create distributed JavaTM technology-based to Java technology-based applications, in which the methods of remote Java objects can be invoked from other Java virtual machines, possibly on different hosts.

  15. More on RMI • Remote Method Invocation (RMI) is the object equivalent of Remote Procedure Calls (RPC). • While RPC allows you to call procedures over a network, RMI invokes an object's methods over a network. • In the RMI model, the server defines objects that the client can use remotely. The clients can now invoke methods of this remote object as if it were a local object running in the same virtual machine as the client.

  16. More RMI… • RMI hides the underlying mechanism of transporting method arguments and return values across the network. • In Java-RMI, an argument or return value can be of any primitive Java type or any other Serializable Java object. • Java-RMI is a Java-specific middleware spec that allows client Java programs to invoke server Java objects as if they were local. • Java-RMI is tightly coupled with the Java language. Hence there are no separate IDL mappings that are required to invoke remote object methods. This is different from DCOM or CORBA where IDL mappings have to be created to invoke remote methods.IDL==Interface Definition Language

  17. RMI contd… • Because of this, parameters passed during method calls between machines can be true Java Objects. This is impossible in DCOM or CORBA at present. • If a process in an RMI system receives an object of a class that it has never seen before, it can request that its class information be sent over the network. • Over and above all this, Java-RMI supports Distributed Garbage Collection that ties into the local Garbage Collectors in each JVM. • Since both the client and the server may reside on different machines/processes, there needs to be a mechanism that can establish a relationship between the two. Java-RMI uses a network-based registry program called RMIRegistry to keep track of the distributed objects. (Note: The RMI Registry is an RMI server itself!!!)

  18. RMI/Remote Interface package SimpleStocks; import java.util.*; import java.rmi.*; public interface StockMarket extends java.rmi.Remote {   float get_price( String symbol ) throws RemoteException; }

  19. RMI/server package SimpleStocks; import java.rmi.*; import java.rmi.server.UnicastRemoteObject; public class StockMarketImplextends UnicastRemoteObject implements StockMarket {   public StockMarketImpl( String name ) throws RemoteException {     try { Naming.rebind( name, this );    }     catch( Exception e ) {       System.out.println( e );     }   }   public float get_price( String symbol ) {     float price = 0;     for( int i = 0; i < symbol.length(); i++ ) {       price += (int) symbol.charAt( i );     }     price /= 5;     return price;   } }

  20. RMI/server-deploy import java.rmi.*; import java.rmi.server.UnicastRemoteObject; import SimpleStocks.*; public class StockMarketServer {   public static void main(String[] args) throws Exception { if(System.getSecurityManager() == null) {       System.setSecurityManager( new RMISecurityManager() );     }     StockMarketImpl myObject = new StockMarketImpl( "NASDAQ" );     System.out.println( "RMI StockMarketServer ready..." );   } }

  21. RMI/policy.all grant {  permission java.security.AllPermission "", ""; };

  22. RMI/server start Compile the Files, generate the stubs & skeletons, startup the RMIRegistry and Run the Server E:\MyProjects\StockRMI\SimpleStocks>E:\MyProjects\StockRMI\SimpleStocks>javac *.javaE:\MyProjects\StockRMI\SimpleStocks>cd..E:\MyProjects\StockRMI>rmic SimpleStocks.StockMarketImplE:\MyProjects\StockRMI>javac *.javaE:\MyProjects\StockRMI>start rmiregistryE:\MyProjects\StockRMI>java -Djava.security.policy=policy.all StockMarketServerRMI StockMarketServer ready...

  23. RMI/client import java.rmi.*; import java.rmi.registry.*; import SimpleStocks.*; public class StockMarketClient {   public static void main(String[] args) {     try { if(System.getSecurityManager() == null) {         System.setSecurityManager( new RMISecurityManager() );       }       StockMarket market = (StockMarket)Naming.lookup("rmi://localhost/NASDAQ");      System.out.println( "The price of MY COMPANY is "                           + market.get_price("MY_COMPANY") );     }     catch( Exception e ) {       System.out.println( e );     }   } }

  24. RMI/policy.all grant {  permission java.security.AllPermission "", ""; };

  25. RMI/run the client Compile the files and run the client E:\MyProjects\StockRMI>E:\MyProjects\StockRMI>javac *.javaE:\MyProjects\StockRMI>java -Djava.security.policy=policy.all StockMarketClientThe price of MY COMPANY is 159.2E:\MyProjects\StockRMI>

  26. Conclusion • We covered quite a few concepts. • Any questions???

More Related