p2p file sharing application with aspect oriented flavor
TRANSCRIPT
-
8/8/2019 P2P File Sharing Application with Aspect Oriented Flavor
1/29
Aspect Oriented Development Of P2P
File Sharing ApplicationEren Algan
Doan Kaya Berkata
Rdvan Tekdoan
-
8/8/2019 P2P File Sharing Application with Aspect Oriented Flavor
2/29
Outline
` Introduction
` Case Study
` Example P2P Application
` Applying Design Patterns
` Identifying Crosscutting Concerns
` Aspect Oriented Implementation
` Conclusion
`
DEMO
-
8/8/2019 P2P File Sharing Application with Aspect Oriented Flavor
3/29
Introduction
` Increase of Internet usage makes P2P file sharingapplications populer
` Many aspects in P2P File Sharing Applications
` Concurreny, fault tolerance, quality of service and
adaptibility.
` Separation of Concerns with
` OOD
` AOD
-
8/8/2019 P2P File Sharing Application with Aspect Oriented Flavor
4/29
Case Study: P2P Application
-
8/8/2019 P2P File Sharing Application with Aspect Oriented Flavor
5/29
Object Oriented Designclass Class Model
User
- fi les: ArrayList
- IP: InetAddress
- port: int
- username: String
+ addFile(String, long) : void
+ getName() : String
+ getPort() : int- li ke(String, String) : boolean
+ search(String) : ArrayList
+ User(String , in t, InetAddress)
+ getIP() : InetAddress
Runnable
Upload
- fil eName: String = "shared/"
- lower: int = -1
- soc: Socket
- upper: long = -1
+ run() : void
+ Upload(String, int, long , Socket)
+ Upload(String, Socket)
P2PServer
- serverPort: in t
- serverSocket: ServerSocket
~ users: ArrayL ist
- communi cate(Socket, InetAddress) : void
+ main (String[]) : void
- P2PServer(int)
- searchName(String) : String
P2PFile
+ name: String
+ size: long
+ P2PFile(String, long)
P2PClient
- localPort: int
- recievePort: int
- serverIP: InetAddress
- serverPort: in t
- username: String = ""
+ main (String[]) : void
- P2PClient(InetAddress, int, int)- run() : void
+ upload() : void
Runnable
Download
- data: byte ([])
- file: String
- ip: InetAddress
- lower: long = -1
- port: int- ready: boolean = false
- tempFil e: String
- upper: long
+ Download(String, InetAddress, int, long, long, String)
+ Download(String, InetAddress, int, long )
+ getData() : byte[]
+ isReady() : boolean
+ run() : void
-
8/8/2019 P2P File Sharing Application with Aspect Oriented Flavor
6/29
Applying Patterns
` Observer Pattern` Active Object Pattern
-
8/8/2019 P2P File Sharing Application with Aspect Oriented Flavor
7/29
What is Observer Pattern
Dont Call Us, Well Call You!
-
8/8/2019 P2P File Sharing Application with Aspect Oriented Flavor
8/29
Subject
` This is basically an interface that enables observers toattach and detach themselves to class that implementsthis interface.
` Holds a list of observers that are subscribed to it
` Attach - Adds a new observer
` Detach - Removes an existing observer
` Notify - Notifies each
-
8/8/2019 P2P File Sharing Application with Aspect Oriented Flavor
9/29
Observer
` Subscribed to Subject
-
8/8/2019 P2P File Sharing Application with Aspect Oriented Flavor
10/29
Active Object Pattern
` Object behavioral pattern` decouples method execution from method invocation in
order to simplify synchronized access to and object thatresides in its own thread of control.
` The Active Object pattern allows one or moreindependent threads of execution to interleave theiraccess to data modeled as a single object.
` Commonly used in distributed systems requiring multi-
threaded servers.
-
8/8/2019 P2P File Sharing Application with Aspect Oriented Flavor
11/29
Active Object Pattern
-
8/8/2019 P2P File Sharing Application with Aspect Oriented Flavor
12/29
class Class M
l
P2PClient::Client
~
= 0
x
x
q !
="
# #
~$ % & ' &
( = "$ % & )
" { &
O
}
# $
!
( = ""
+ 0 1 2
+&
3
&
1
4
3
&
2
&
+& 3 &
M
1
(
5 6
$
<
( >2 &
+ & 3
&
(
1
(
5 7
6
& &
$ $
5
5
( 2
&
+ ! 1 ( 8 9 2 &
~ run() : void
+
&
1
(
5 5
(
5 # @
2
&
+
&
1 2
&
P2PClient::A
ownloadRequest
- part: DownloadPart
- priority: float
- servant: Client
+ call() : void
+ canRun() : boolean
+ DownloadRequest(Client, DownloadPart, float)
+ getPriority() : float
P2PClient::Schedular
- activationList: PriorityQueue= new PriorityQue...
- active: int =0
- limit: int
- get() : IMethodRequest
+ insert(IMethodRequest) : void
+ Schedular(int)
P2PClient::ServantProxy
- schedula r: Schedul ar
- servant: Client
+ download(DownloadPart, float) : void
+ ServantProxy(Client, int)
+ upload(String, int, long, S ocket, float) : void
P2PClient::UploadRequest
- file: String
- lower: int
- priority: float
- servant: Clien t
- socket: Socket
- upper: long
+ call() : void
+ canRun() : boolean
+ getPriority() : fl oat
+ UploadRequest(Client, String, int, long, Socket, float)
interface
P2PClient::IMethodRequest
+ call() : void
+ canRun() : boo lean
+ getPriority() : float
-proxy
-servant
-servant
-servant
-schedular
-
8/8/2019 P2P File Sharing Application with Aspect Oriented Flavor
13/29
Identfying Crosscutting Concerns
` Observing Object State Changes` Creation of Worker Objects
` Monitoring
-
8/8/2019 P2P File Sharing Application with Aspect Oriented Flavor
14/29
Aspect Oriented Version
` Empty Subject & Observer interfaces` Assigned according to their roles
-
8/8/2019 P2P File Sharing Application with Aspect Oriented Flavor
15/29
Tracking of Observers
` Normally, the participants keeps track of the observersthat listening to a particular subject.
` Instead centralized via ObserverProtocol aspect
-
8/8/2019 P2P File Sharing Application with Aspect Oriented Flavor
16/29
protected List getObservers(Subject subject)
{
if (perSubjectObservers == null){
perSubjectObservers = newWeakHashMap();
}
List observers = (
List)perSubjectObservers.get(subject);
if ( observers == null )
{
observers = new LinkedList();
perSubjectObservers.put(subject, observers);
}
return observers;
}
-
8/8/2019 P2P File Sharing Application with Aspect Oriented Flavor
17/29
void addObserver(Subject subject, Observer observer)
{
getObservers(subject).add(observer);
}
v
oid removeObserver(Subject subject, Observer observer){
getObservers(subject).remove(observer);
}
-
8/8/2019 P2P File Sharing Application with Aspect Oriented Flavor
18/29
Notifying the Observers
` The OO way of doing is via subject.` Subject calls every observers update method.
` Aspect oriented version is also using a loop to callobservers update methods, but this time from the aspect.
-
8/8/2019 P2P File Sharing Application with Aspect Oriented Flavor
19/29
protected abstract pointcut subjectChange(Subject s);
after(Subject subject) returning : subjectChange(subject)
{
for (Observer observer : getObservers(subject))
{updateObserver(subject, observer);
}
}
-
8/8/2019 P2P File Sharing Application with Aspect Oriented Flavor
20/29
Role Assignments
declare parents : FolderWatcher extends Subject;
declare parents : DownloadManager implements
Observer;
Handled via aspect
Without any interference with modifying
classes directly.
-
8/8/2019 P2P File Sharing Application with Aspect Oriented Flavor
21/29
Starting the Observation Relationship
// used for injection
private MainFrame defaultObserver =MainFrame.newContentPane;
pointcut folderWatcherCreation(Subject s) :execution(public FolderWatcher+.new(..))
&& this(s);
after(Subject s) returning : folderWatcherCreation(s)
{
addObserver(s, defaultObserver);
}
-
8/8/2019 P2P File Sharing Application with Aspect Oriented Flavor
22/29
Creation ofWorker Objects
public class Downloadextends Runnable
{public Download(..)
{
..
}
public void run()
{// Core aspect
}
}
public void download(..)
{
Thread t = newThread(){
publicv
oid run(){// Core aspect
}
};
t.start();
}
-
8/8/2019 P2P File Sharing Application with Aspect Oriented Flavor
23/29
-
8/8/2019 P2P File Sharing Application with Aspect Oriented Flavor
24/29
AO Solution: Creation ofWorker Object
public abstract aspect
AsynchronousExecutionAspect {abstract pointcut asyncOperations();
Object around():asyncOperations(){
Runnable worker = new Runnable() {
public void run() {proceed();
}
};
newThread(worker).start();
return null;
}
}public aspect Concurrency extendsAsynchronousExecutionAspect{
pointcut asyncOperations():call(@Asynchronous * *(..));
}
-
8/8/2019 P2P File Sharing Application with Aspect Oriented Flavor
25/29
Monitoring
` Some actions trigger state changes in objects` When a file download completed, GUI must change
status of corresponding Download object to completed.
` Total data uploaded and downloaded used for
determining priority
-
8/8/2019 P2P File Sharing Application with Aspect Oriented Flavor
26/29
-
8/8/2019 P2P File Sharing Application with Aspect Oriented Flavor
27/29
AO Solution: Monitoringaspect Monitoring {
long Client.totalUpload = -1;long Client.totalDownload = 1;
after(Client c,byte[] data, int off, int len): this(c)&&call(void
java.io.DataOutputStream.write(byte[],int,int)) && args(data,off,len){
c.totalUpload += len;
}
after(Client p) returning(int retval) : this(p) && call(intjava.io.DataInputStream.read(..)){
p.totalDownload += retval;
}
after(Client p):target(p) &&(set(long Client.totalUpload) || set(long Client.totalDownload)){
if(p.totalDownload> 0) {
p.priority= p.totalUpload/ p.totalDownload;
}
}
after(Download d) : target(d) && set(long Download.downloaded){
d.downloadFlagChanged = true;
}
-
8/8/2019 P2P File Sharing Application with Aspect Oriented Flavor
28/29
Conclusion
` Enhancing existing application by applying Design Patterns` Crosscutting Concerns
` Observing Object State Changes
` Creation Object Worker Objects
` Monitoring
` OOD not suitable for crosscutting concerns
` AO solutions for crosscutting concerns
-
8/8/2019 P2P File Sharing Application with Aspect Oriented Flavor
29/29
DEMO