Skip to main content

Featured

Adobe Experience Manager - Create an OSGI Configuration

 In this article, let's create an OSGi configuration, configure it and use it in AEM code. So now let's get started with the creation of an OSGi configuration. Technical details and Assumptions: All the following details are tested in AEM version 6.5.8, Java version 11.0.2 Creation of OSGi configuration: To create an OSGi configuration we need to create an ObjectClassDefinition. I have included a sample OCD configuration, which can be used as a reference to create one. The next step would be to create an interface and an implementation that can help fetch the OSGi configurations.  Interface: Implementation: Let's try to use the OSGi configuration created so far in Models/Servlets. For demonstration purposes, I used AEM Models here, but the same can be implemented in Servlets too. Now that we have created the OSGi configuration. Once building the code, we should be able to see the OSGi configuration in the web console (http://localhost:4502/system/console/configMgr) C...

Implementation of Stop and Wait Protocol

This java program helps in implementing the stop and wait protocol. which is a special case of sliding window protocol with window size one. Where each data sent is acknowledged by the receiver.

server1.java:

import java.io.*;
import java.net.*;
public class server1{
public static void main(String args[])throws IOException{
ServerSocket sc = new ServerSocket(5000);
Socket s = sc.accept();
BufferedReader br1,br2;
String s1,s2;
PrintStream ps;
while(true){
br1 = new BufferedReader(new InputStreamReader(System.in));
s1 = br1.readLine();
if(s1 == "bye"){
    ps = new PrintStream(s.getOutputStream());
    ps.println("bye");
    break;
}
else{
System.out.println("The Data to be sent is "+s1);
ps = new PrintStream(s.getOutputStream());
ps.println(s1);
br2 = new BufferedReader(new InputStreamReader(s.getInputStream()));
s2 = br2.readLine();
System.out.println(s2);
}
}
s.close();
}
}

client1.java:

import java.io.*;
import java.net.*;
public class client1{
public static void main(String args[])throws IOException{
Socket sc = new Socket("127.0.0.1",5000);
BufferedReader br1,br2;
String s1,s2;
PrintStream ps;
while(true){
br1 = new BufferedReader(new InputStreamReader(sc.getInputStream()));
s1 = br1.readLine();
if(s1.equals("bye")){
    break;
}
else{
System.out.println("Data received is "+s1);
s2 = "Data Acknowledged is "+s1;
System.out.println(s2);
ps = new PrintStream(sc.getOutputStream());
ps.println(s2);
}
}
sc.close();
}
}

Output:

Comments

Popular Posts