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 Sliding Window Protocol

This Java Program implements Sliding Window Protocol with the window size fixed at the client. The Server sents the exactly the number of data that the Client can receive. 

server1.java:

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

client1.java:

import java.io.*;
import java.util.*;
import java.net.*;
public class client1{
public static void main(String args[])throws IOException{
Socket sc = new Socket("127.0.0.1",5002);
BufferedReader br1,br2;
int count,d,e=0;
String s1,s2,s4;
PrintStream ps;
Scanner in = new Scanner(System.in);
count = in.nextInt();
String[] s3 = new String[count];
ps = new PrintStream(sc.getOutputStream());
ps.println(count);
while(true){
    for(d=0;d<count;d++){
br1 = new BufferedReader(new InputStreamReader(sc.getInputStream()));
s1 = br1.readLine();
if(s1.equals("bye")){
    e=1;
    break;
}
else{
s3[d] = s1;
    }}
if(e == 1){
    break;
}
else{   
s4 = String.join(", ",s3);
System.out.println("Data received is "+s4);
s2 = "Data Acknowledged is "+s4;
ps = new PrintStream(sc.getOutputStream());
ps.println(s2);
}
}
sc.close();
}
}

Output:

Comments

Popular Posts