You are on page 1of 17

QN: what is middleware and its types

Middleware systems comprised of abstractions and services to facilitate design


development integration and deployment of distributed applications in
heterogenous networking environment

Middleware is the software "glue" that helps programs and databases that may be
on different computers work together.These are done using remote communication
mechanisms

Eg : Webservices , CORBA , JAVA RMI, COM, Event notification, messaging


services (JMS), Transaction services, naming services

 #Message-oriented middleware (MOM) enables application components


using different messaging protocols to communicate to exchange messages.
In addition to translating - or transforming - messages between applications,
MOM manages routing of the messages so they always get to the proper
components in the in the proper order. Examples of MOM include message
queues and message brokers.
 #Remote procedure call (RPC) middleware enables one application to
trigger a procedure in another application - running on the same computer or
on a different computer or network - as if both were part of the same
application on the same computer.
 Data or database middleware simplifies access to, and interaction with,
back-end databases. Typically database middleware is some form of SQL
database server.
 API (application programming interface) middleware provides tools
developers can use to create, expose and manage APIs for their
applications - so that other developers can connect to them. Some
API middleware includes tools for monetizing APIs - enabling other
organizations to use them, at cost. Examples of API middleware include API
management platforms, API gateways and API developer portals.
 #Object request broker (ORB) middleware acts as broker between a
request from one application object or component, and the fulfillment of that
request by another object or component on the distributed network. ORBs
operate with the Common Object Request Broker Architecture (CORBA),
which enables one software component to make a request of another
without knowing where other is hosted, or what its UI looks like - the
"brokering" handles this information during the exchange.
 #Transactional middleware provides services to support the execution of
data transactions across a distributed network. The best-known transactional
middleware are transaction processing monitors (TPMs), which ensure that
transactions proceed from one step to the next - executing the data
exchange, adding/changing/deleting data where needed, etc. - through to
completion.
 Asynchronous data streaming middleware replicates a data stream in an
intermediate store, enabling data sharing between multiple
applications. Apache Kafka is one of the best-known examples of
middleware for real-time data streaming.
 Device middleware provides a focused set of integration and
connectivity capabilities for developing apps for a specific mobile OS.
 Portal middleware provides tools and resources for integrating content and
capabilities from various related applications 'at the glass' - or on a single
screen - to create a single, composite application.
 Robotics middleware simplifies the process of integrating robotic hardware,
firmware and software from multiple manufacturers and locations.

QN: outline steps to access a relational db using JDBC.develop a java


application to perform DML operations on the following relations

Employee(eno,name,dno)

Department(dno,dname)

package simplejdbc;

//Importing necessary packages

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.Statement;

import java.sql.ResultSet;

public class SimpleJDBC {

public static void main(String[] args) {

try{

//Load the JDBC Driver

Class.forName("com.mysql.cj.jdbc.Driver");

//Connection establishment //URL Username Password

Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/bd","root","goldBlock@1234");

//Creating a statement object

Statement stmt=con.createStatement();

//Insertion
stmt.executeUpdate("INSERT INTO DEPARTMENT VALUES (1004,'Security')");

stmt.executeUpdate("INSERT INTO EMPLOYEE VALUES (10004,'Rani',1003)");

//Reading from an existing table into a result set

ResultSet rs=stmt.executeQuery("select * from DEPARTMENT");

//Looping through every row data

while(rs.next())

//printing the row data

System.out.println(rs.getInt(1)+" "+rs.getString(2));

rs=stmt.executeQuery("select * from EMPLOYEE");

while(rs.next())

System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));

//Update statement

stmt.executeUpdate("UPDATE DEPARTMENT SET DNAME='Protection' WHERE DNO


=1004");

//Delete statement

stmt.executeUpdate("DELETE FROM DEPARTMENT WHERE DNO=1004");

//Connection close

con.close();

}catch(Exception e){ System.out.println(e);}

}
QN:OUTLINE THE PROCEDURE OF REMOTE PROCEDURE CALL WITH
A DIAGRAM

Remote Procedure Call (RPC) is a communication technology that is


used by one program to make a request to another program for
utilizing its service on a network without even knowing the network’s
details. A function call or a subroutine call are other terms for a
procedure call.

It is based on the client-server concept. The client is the program


that makes the request, and the server is the program that gives the
service. An RPC, like a local procedure call, is based on the
synchronous operation that requires the requesting application to be
stopped until the remote process returns its results.

Working Procedure for RPC Model:

• The process arguments are placed in a precise location by the


caller when the procedure needs to be called.

• Control at that point passed to the body of the method, which


is having a series of instructions.

• The procedure body is run in a recently created execution


environment that has duplicates of the calling instruction’s
arguments.
• At the end, after the completion of the operation, the calling
point gets back the control, which returns a result.

• The call to a procedure is possible only for those procedures


that are not within the caller’s address space because both processes
(caller and callee) have distinct address space and the access is
restricted to the caller’s environment’s data and variables from the
remote procedure.

• The caller and callee processes in the RPC communicate to


exchange information via the message-passing scheme.

• The first task from the server-side is to extract the procedure’s


parameters when a request message arrives, then the result, send a
reply message, and finally wait for the next call message.

• Only one process is enabled at a certain point in time.

• The caller is not always required to be blocked.

• The asynchronous mechanism could be employed in the RPC


that permits the client to work even if the server has not responded
yet.

• In order to handle incoming requests, the server might create a


thread that frees the server for handling consequent requests.
Types of RPC:

• Callback RPC

• RPC for Broadcast

• Batch-mode RPC

Qn:outline tcp and udp sockets with code in java

Tcp client

import java.io.*;

import java.net.*;

public class MyClient {

public static void main(String[] args) {


try{

Socket s=new Socket("localhost",6666);

DataOutputStream dout=new
DataOutputStream(s.getOutputStream());

dout.writeUTF("Hello Server");

dout.flush();

dout.close();

s.close();

}catch(Exception e){System.out.println(e);}

TCP server

import java.io.*;

import java.net.*;

public class MyServer {

public static void main(String[] args){

try{

ServerSocket ss=new ServerSocket(6666);


Socket s=ss.accept();//establishes connection

DataInputStream dis=new DataInputStream(s.getInputStream());

String str=(String)dis.readUTF();

System.out.println("message= "+str);

ss.close();

}catch(Exception e){System.out.println(e);}

Udp client

// Java program to illustrate Client side

// Implementation using DatagramSocket

import java.io.IOException;

import java.net.DatagramPacket;

import java.net.DatagramSocket;

import java.net.InetAddress;

import java.util.Scanner;

public class udpBaseClient_2


{

public static void main(String args[]) throws IOException

Scanner sc = new Scanner(System.in);

// Step 1:Create the socket object for

// carrying the data.

DatagramSocket ds = new DatagramSocket();

InetAddress ip = InetAddress.getLocalHost();

byte buf[] = null;

// loop while user not enters "bye"

while (true)

String inp = sc.nextLine();

// convert the String input into the byte array.


buf = inp.getBytes();

// Step 2 : Create the datagramPacket for sending

// the data.

DatagramPacket DpSend =

new DatagramPacket(buf, buf.length, ip,


1234);

// Step 3 : invoke the send call to actually send

// the data.

ds.send(DpSend);

// break the loop if user enters "bye"

if (inp.equals("bye"))

break;

}
UDP server

// Java program to illustrate Server side

// Implementation using DatagramSocket

import java.io.IOException;

import java.net.DatagramPacket;

import java.net.DatagramSocket;

import java.net.InetAddress;

import java.net.SocketException;

public class udpBaseServer_2

public static void main(String[] args) throws IOException

// Step 1 : Create a socket to listen at port 1234

DatagramSocket ds = new DatagramSocket(1234);

byte[] receive = new byte[65535];

DatagramPacket DpReceive = null;


while (true)

// Step 2 : create a DatgramPacket to receive the


data.

DpReceive = new DatagramPacket(receive,


receive.length);

// Step 3 : revieve the data in byte buffer.

ds.receive(DpReceive);

System.out.println("Client:-" + data(receive));

// Exit the server if the client sends "bye"

if (data(receive).toString().equals("bye"))

System.out.println("Client sent
bye.....EXITING");

break;
}

// Clear the buffer after every message.

receive = new byte[65535];

// A utility method to convert the byte array

// data into a string representation.

public static StringBuilder data(byte[] a)

if (a == null)

return null;

StringBuilder ret = new StringBuilder();

int i = 0;

while (a[i] != 0)

ret.append((char) a[i]);
i++;

return ret;

Qn: what is remote method invocation?outline RMI using java


application.

Remote Method Invocation (RMI) is an API that allows an object to


invoke a method on an object that exists in another address space,
which could be on the same machine or on a remote machine

HelloInterface.java

import java.rmi.registry;

import java.rmi.registry.LocateRegistry;

import java.rmi.registry.remote;

public interface HelloInterface extends Remote

public String say(int age) throws RemoteException;

}
Hello.java

import java.rmi.registry;

import java.rmi.registry.LocateRegistry;

import java.rmi.registry.remote;

import java.rmi.server.*;

public class Hello extends UnicastRemoteObject implements


HelloInterface {

public String say(int age) throws RemoteException {

if(age>=18)

return ("can vote");

return ("cannot vote");

HelloServer.java

import java.io.*;

import java.rmi.registry;

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.remote;

public class HelloServer{

public static void main (String[] args) {

try {

Naming.rebind ("SHello", new Hello ());

System.out.println ("HelloServer is ready.");

catch (Exception e) {

System.out.println ("HelloServer failed: " + e);

Helloclient.java

import java.io.*;

import java.rmi.registry;

import java.rmi.registry.LocateRegistry;

import java.rmi.registry.remote;

import jav.util.Scanner;
public class HelloClient{

public static void main (String[] args) {

try {

HelloInterface hello = (HelloInterface)


Naming.lookup ("SHello");

System.out.println ("enter age");

Scanner sc=new Scanner(System.in);

int age=sc.nextInt();

System.out.println(hello.say(age));

catch (Exception e) {

System.out.println ("HelloClient failed: " + e);

You might also like