\input{configpres}

\title{\lq Middleware\rq}
\maketitle

\begin{frame}
\frametitle{Agenda}
\begin{itemize}
\item Overview
\item XML based Middleware
\item Celery
\item D-Bus
\item CORBA
\end{itemize}
GOAL: get an idea about:

the amount of available middleware solutions

and for what they can be used.
\end{frame}

\subsection{Overview}

\begin{frame}
\frametitle{Use-case}
\begin{center}
\includegraphics[width=0.8\textheight]{images/714px-Middleware_Schema.png}
\end{center}
\tiny Source: http://commons.wikimedia.org/wiki/File:Middleware\_Schema.svg
\end{frame}

\begin{frame}
\frametitle{Why should we use a middleware?}
\begin{itemize}
\item IPC
\item scalability
\item os abstraction
\item reusability of sw components
\end{itemize}
\end{frame}

\begin{frame}
\frametitle{Kinds of Middleware}
\begin{itemize}
\item Message Oriented Middleware (MOM)
\item Remote Procedure Calls (RPC)
\item Webapplications?
\end{itemize}
\end{frame}

\begin{frame}
\frametitle{Requirements}
\begin{block}{Abstraction Layers}
\begin{itemize}
\item operating system
\item programing language
\item localization
\item transport
\item concurrent access
\end{itemize}
\end{block}
\end{frame}

\begin{frame}
\frametitle{Requirements}
\begin{block}{Technical, product specific}
\begin{itemize}
\item os / language support
\item performance
\item requirement coverage
\item commerical, open-source, (long-time) support
\end{itemize}
\end{block}
\end{frame}

\begin{frame}
\frametitle{Standards, Protocols}
\begin{itemize}
\item XML based Middleware
\item Celery - Job Queue Protocol
\item D-Bus - MOM
\item CORBA - Common Object Request Broker
\end{itemize}
\end{frame}

\subsection{XML based Middleware}
\begin{frame}
\frametitle{popular protocols}
\begin{description}
\item[XML-RPC] Extensible Markup Language Remote Procedure Call
\item[SOAP/WSDL] many webservices are based on SOAP
\item[XMPP] Extensible Messaging and Presence Protocol
\end{description}
\end{frame}

\begin{frame}
\frametitle{XML-RPC}
\begin{itemize}
\item native supported by Python (see example)
\item C/C++ Implementation: http://xmlrpc-c.sourceforge.net/
\item Client- / Serverarchitecture
\item uses http as transport
\end{itemize}
\end{frame}

\begin{frame}[fragile]
\frametitle{XML-RPC example in Python}
server.py\#p1
\begin{lstlisting}[language=python]
from datetime import datetime
from SimpleXMLRPCServer import SimpleXMLRPCServer
import xmlrpclib

def today ():
    today = datetime.today ()
    return xmlrpclib.DateTime (today)

def load ():
    fd = open ("/proc/loadavg", "r")
    loadavg = fd.read ()
    sysload = loadavg.split ()
    return xmlrpclib.FloatType (sysload[0])
\end{lstlisting}
\end{frame}

\begin{frame}[fragile]
\frametitle{XML-RPC example in Python}
server.py\#p2
\begin{lstlisting}[language=python]
server = SimpleXMLRPCServer (("localhost",
                              8000))

server.register_function (today, "today")
server.register_function (load, "load")

print "Listening on port 8000..."
server.serve_forever ()
\end{lstlisting}
\end{frame}


\begin{frame}[fragile]
\frametitle{XML-RPC example in Python}
client.py\#p1
\begin{lstlisting}[language=python]
import xmlrpclib
from datetime import datetime

proxy = xmlrpclib.ServerProxy (
                    "http://localhost:8000/")
\end{lstlisting}
\end{frame}

\begin{frame}[fragile]
\frametitle{XML-RPC example in Python}
client.py\#p2
\begin{lstlisting}[language=python]
today = proxy.today ()
# today = 20140218T14:23:45

conv = datetime.strptime (today.value,
                          "%Y%m%dT%H:%M:%S")

print "Today:", conv.strftime (
                          "%d.%m.%Y, %H:%M")

load = proxy.load ()
print "system load:", load
\end{lstlisting}
\end{frame}

\begin{frame}[fragile]
\frametitle{XML-RPC example in Python}
output:
\begin{lstlisting}[language=bash]
 % python client.py
Today: 18.02.2014, 14:26
system load: 0.45
\end{lstlisting}
\end{frame}

\begin{frame}[fragile]
\frametitle{XML-RPC example in Python}
http payload of today rpc call seen in wireshark:
\begin{lstlisting}[language=XML]
<?xml version='1.0'?>
<methodCall>
    <methodName>today</methodName>
    <params></params>
</methodCall>
\end{lstlisting}
\end{frame}

\begin{frame}[fragile]
\frametitle{XML-RPC example in Python}
http payload of today rpc response seen in wireshark:
\begin{lstlisting}[language=XML]
<?xml version='1.0'?>
<methodResponse>
  <params>
    <param>
      <value>
        <dateTime.iso8601>
          20140218T14:26:25
        </dateTime.iso8601>
      </value>
    </param>
  </params>
</methodResponse>
\end{lstlisting}
\end{frame}

\begin{frame}
\frametitle{SOAP/WSDL}
\begin{block}{Overview}
\begin{itemize}
\item WSDL (Web Services Description Language)

describes the interface and spcecial datatypes
\item the SOAP protocol is used for communication
\item SOAP can be used with various transports:

FTP, SMTP, HTTP(S), JMS
\item hopping is supported, with different transports
\item Client- / Serverarchitecture
\end{itemize}
\end{block}
\end{frame}

\begin{frame}
\frametitle{SOAP/WSDL}
\begin{block}{Implementations}
\begin{itemize}
\item ZSI: Python
\item KDSOAP: Qt4/5 native Library (commercial)
\item gSOAP: C/C++
\item Apache Axis2: C++, JAVA
\item Apache CXF: JAVA (+ other middleware protocols)
\item SOAP::WSDL: Perl
\item SOAP4R: Ruby
\item wsdl2objc: Objective C
\item .NET, mono
\end{itemize}
\end{block}
\end{frame}

\begin{frame}[fragile]
\frametitle{SOAP example in Python/ZSI}
server.py
\begin{lstlisting}[language=python]
from datetime import datetime
from ZSI import dispatch

def today (arg):
    print "today arg:", arg
    today = datetime.today ()
    return str (today)
def load (arg):
    print "load arg:", arg
    fd = open ("/proc/loadavg", "r")
    loadavg = fd.read ()
    sysload = loadavg.split ()
    return sysload[0]

dispatch.AsServer (port=8000, rpc=True)
\end{lstlisting}
\end{frame}

\begin{frame}[fragile]
\frametitle{SOAP example in Python/ZSI}
client.py
\begin{lstlisting}[language=python]
from datetime import datetime
from ZSI.client import Binding

b = Binding (url='http://localhost:8000/')
t = b.today (5)
# t = 2014-02-18 15:59:50.571927
c = datetime.strptime (t,
                       "%Y-%m-%d %H:%M:%S.%f")
print "Today:", c.strftime ("%d.%m.%Y, %H:%M")
print b.load ("string")
\end{lstlisting}
\end{frame}


\begin{frame}
\frametitle{XMPP - Extensible Messaging and Presence Protocol}
\begin{block}{Overview}
\begin{itemize}
\item protocol for MOM based on XML
\item originally named Jabber
\item used for
\begin{itemize}
  \item real-time Instant Messaging
  \item publishing Presence Informations
  \item Contactlist maintenance
\end{itemize}
\end{itemize}
\end{block}
\end{frame}


\begin{frame}
\frametitle{Extensible Messaging and Presence Protocol}
\begin{block}{IM for Industry??}
\begin{itemize}
\item free and open standard (IETF RFC 6120, 6121)
\item XMPP servers can be isolated, security is implemented (SASL, TLS)
\item TCP and HTTP(S) transports are supported
\item Priority support: multiple logins from same account,

login with highest pority gets message
\item not just used for IM:
\begin{itemize}
  \item smart grid
  \item publish-subscribe systems
  \item games
  \item signalling for VoIP
\end{itemize}
\end{itemize}
\end{block}
\end{frame}

\begin{frame}
\frametitle{Extensible Messaging and Presence Protocol}
\begin{block}{Extensible\dots}
\begin{itemize}
\item network management
\item collaboration tools
\item file sharing, gaming
\item remote systems control and monitoring
\item geolocation
\end{itemize}
\end{block}
\end{frame}

\begin{frame}
\frametitle{Extensible Messaging and Presence Protocol}
\begin{block}{Implemmentations}
\dots too many to mention, have a look at

http://xmpp.org/xmpp-software/

for libraries, clients and servers
\end{block}
\end{frame}


\begin{frame}[fragile]
\frametitle{XMPP Client Example}
xmpp\_client.cpp
\begin{lstlisting}[language=C++]
#include <QtCore/QCoreApplication>
#include "myclient.h"

int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);

    MyClient client;
    client.connectToServer("qtapp@localhost",
                           "test");

    return app.exec();
}
\end{lstlisting}
\end{frame}

\begin{frame}[fragile]
\frametitle{XMPP Client Example}
myclient.h
\begin{lstlisting}[language=C++]
#include <qxmpp/QXmppClient.h>

class MyClient : public QXmppClient
{
    Q_OBJECT

    public:
        MyClient();
        ~MyClient();

    public slots:
        void message_rx(const QXmppMessage&);
};
\end{lstlisting}
\end{frame}

\begin{frame}[fragile]
\frametitle{XMPP Client Example}
myclient.cpp\#p1
\begin{lstlisting}[language=C++]
#include <qxmpp/QXmppMessage.h>
#include <iostream>

#include "myclient.h"

MyClient::MyClient() : QXmppClient()
{
  bool check = connect(this,
    SIGNAL(messageReceived(QXmppMessage)),
    SLOT(message_rx(QXmppMessage)));

  Q_ASSERT(check);
  Q_UNUSED(check);
}
\end{lstlisting}
\end{frame}

\begin{frame}[fragile]
\frametitle{XMPP Client Example}
myclient.cpp\#p2
\begin{lstlisting}[language=C++]
MyClient::~MyClient() { ; }

void
MyClient::message_rx(const QXmppMessage& msg)
{
  QString from = msg.from();
  QString body = msg.body();

  std::cout<<from.toStdString()<<": ";
  std::cout<<body.toStdString()<<std::endl;

  sendPacket(QXmppMessage("",from,body+"??"));
}
\end{lstlisting}
\end{frame}


\begin{frame}[fragile]
\frametitle{XMPP Client Example}
\begin{itemize}
\item start ejabberd
\item start psi
\item start QT XMPP Client
\item in psi: write a message to qtapp
\item with wireshark can be seen that the connection is encrypted
\end{itemize}
\end{frame}


\subsection{Celery}

\begin{frame}
\frametitle{Overview}
\begin{itemize}
\item Distributed Task Queue
\item based on message passing
\item real-time operation and scheduling
\item Tasks can be hosted on a single or on mulitple workers
\item synchronous and asynchronous execution
\item rate limit support
\end{itemize}
\end{frame}

\begin{frame}
\frametitle{implementations}
\begin{itemize}
\item celery-project: Python
\item celery-php: PHP
\end{itemize}
\end{frame}

\begin{frame}
\frametitle{celeryproject}
\begin{block}{supports multiple message broker}
\begin{itemize}
\item database: Django, or any supported by SQLAlchemy
\item RabbitMQ
\item Redis
\item Amazon SQS (experimental)
\end{itemize}
\end{block}
\end{frame}

\begin{frame}
\frametitle{celeryproject}
\begin{block}{supports multiple result storage}
\begin{itemize}
\item database: any supported by SQLAlchemy
\item memcached
\item Redis
\item AMQP
\item Cassandra
\item IronCache
\end{itemize}
\end{block}
\end{frame}

\begin{frame}[fragile]
\frametitle{celeryproject, example}
exec\_task.py
\begin{lstlisting}{language=python}
import os
from celery import Celery

app = Celery ('tasks', broker='sqla+sqlite:///celerydb.sqlite)

@app.task
def execute (command):
    os.system (command)
\end{lstlisting}
\end{frame}

\begin{frame}[fragile]
\frametitle{celeryproject, example}
test.py
\begin{lstlisting}{language=python}
from exec_task import execute

execute.delay ("echo hello world")
\end{lstlisting}

start the example:
\begin{lstlisting}{language=bash}
term1% celery -A exec_task worker
term2% ./test.py
\end{lstlisting}
\dots an example using return values and exceptions is in the example dir
\end{frame}


\subsection{D-Bus}

\begin{frame}
\frametitle{D-Bus Communication Framework}
\begin{block}{Facts}
\begin{itemize}
\item used by GNOME, KDE4, E17, XFCE4 and many applications
\item for message based local IPC
\item provides 1:1 - 1:n message passing
\item there is a system and a session bus
\end{itemize}
\end{block}
\end{frame}

\begin{frame}
\frametitle{D-Bus Communication Framework}
\begin{block}{Language Support}
\begin{itemize}
\item C / C++ / Objective-C
\item JAVA
\item Python
\item Perl
\item PHP
\item Pascal
\item Ruby
\item Smalltalk
\end{itemize}
\end{block}
\end{frame}

\begin{frame}
\frametitle{D-Bus Communication Framework}
\begin{block}{Framework Support}
\begin{itemize}
\item QT (C++ / Python)
\item GLib (GDBus)
\item .NET (mono)
\item edbus (Enlightenment, E17)
\end{itemize}
\end{block}
\end{frame}

\begin{frame}[fragile]
\frametitle{Desktop Integration}
open home directory with the e17 file manager
\begin{verbatim}
% mdbus2 -i
MDBUS2> org.enlightenment.FileManager \
        /org/enlightenment/FileManager \
        org.enlightenment.FileManager.OpenDirectory \
        /home/local
\end{verbatim}
\end{frame}

\begin{frame}[fragile]
\frametitle{System Integration}
e.g. hotplug events
\begin{verbatim}
% mdbus2 -s -l
[SIGNAL]
org.freedesktop.UDisks.DeviceAdded
/org/freedesktop/UDisks  :1.25
('/org/freedesktop/UDisks/devices/sdb',)
\end{verbatim}
\end{frame}

\begin{frame}[fragile]
\begin{verbatim}
[SIGNAL]
org.freedesktop.DBus.ObjectManager.InterfacesAdded
/org/freedesktop/UDisks2  :1.40
('/org/freedesktop/UDisks2/drives/WD_My_Passport_0748_57584D314335325839363238',
{'org.freedesktop.UDisks2.Drive':
  {'Vendor': <'WD'>, 'Model': <'My Passport0748'>,
   'Revision': <'1015'>, 'Serial': <'57584D314335325839363238'>,
   'WWN': <''>, 'Id': <'WD-My-Passport-0748-57584D314335325839363238'>,
   'Configuration': <@a{sv} {}>, 'Media': <''>,
   'MediaCompatibility': <@as []>, 'MediaRemovable':<false>,
   'MediaAvailable': <true>, 'MediaChangeDetected': <true>,
   'Size':<uint64 1000170586112>,
   'TimeDetected': <uint64 1392720111627238>,
   'TimeMediaDetected': <uint64 1392720111627238>,
   'Optical': <false>, OpticalBlank': <false>,
   'OpticalNumTracks': <uint32 0>,
   'OpticalNumAudioTracks': <uint32 0>,
   'OpticalNumDataTracks': <uint32 0>,
   'OpticalNumSessions': <uint32 0>,
   'RotationRate': <-1>, 'ConnectionBus':<'usb'>,
   'Seat': <'seat0'>, 'Removable': <true>, 'Ejectable': <false>,
   'SortKey': <'01hotplug/1392720111627238'>,
   'CanPowerOff': <true>,
   'SiblingId':<'/sys/devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0'>}})
\end{verbatim}
\end{frame}

\begin{frame}[fragile]
\frametitle{Example: Session Bus Signals}
\begin{itemize}
\item have a look at the code
\item start pingserver and pingclient
\item monitor signals with 'mdbus2 -l'
\end{itemize}
\end{frame}

\subsection{CORBA}

\begin{frame}
\frametitle{Common Object Request Broker Architecture}
\begin{itemize}
\item hosting of objects / RPC
\item typically a Client- / Serverarchitecture
\item one application can be Client and Server at the same time
\end{itemize}
\end{frame}


\begin{frame}
\frametitle{well-known implementations}
\begin{itemize}
\item omniORB: C++ / Python
\item ACE/TAO: C++ including RTCORBA support
\item MICO: C++ focus on security
\item JacORB: JAVA
\item IIOP.NET: .NET Remoting integration
\item ORBit2: C with C++ and Python bindings
\end{itemize}
\end{frame}


\begin{frame}
\frametitle{communication between different operating systems}
\begin{itemize}
\item hosting of objects is abstracted, e.g. ThreadPool
\item use of OS services, e.g. sockets is abstracted
\end{itemize}
\end{frame}


\begin{frame}
\frametitle{communication between programming languages}
\begin{itemize}
\item CORBA uses its own datatypes
\item datatype mapping needs to be implement for each language
\end{itemize}
\end{frame}


\begin{frame}
\frametitle{common transports}
\begin{itemize}
\item IIOP
\item socket
\item shared-memory
\item implementing own transports is possible
\end{itemize}
\end{frame}


\begin{frame}
\frametitle{Functional Principle}
\begin{center}
\includegraphics[width=1.0\textwidth]{images/orb.jpg}
\end{center}
\end{frame}


\begin{frame}
\frametitle{Functional Principle}
\begin{block}{IDL Interface Description Language}
\begin{itemize}
\item write Interface Description
\item use IDL compiler to produce stubs and skeleton code
\item implement interfaces and use interfaces in native language
\item compile applications
\end{itemize}
\end{block}
\end{frame}

\begin{frame}
\frametitle{Functional Principle}
\begin{block}{Policies}
\begin{itemize}
\item Server- or Clientsiede Policies
\item Run-time and compile-time Policies
\item e.g. for
\begin{itemize}
\item Lifetime of objects
\item Activation of objects
\item Thread Policies
\item Connection Polies
\end{itemize}
\end{itemize}
\end{block}
\end{frame}

\begin{frame}
\frametitle{Functional Principle}
\begin{block}{CORBA Services}
\begin{itemize}
\item Naming Service
\begin{itemize}
\item Task A: bind object ior with name to Naming Service
\item Task B: resolve object ior by name from Naming Service
\end{itemize}
\item Messaging Service
\begin{itemize}
\item Task A: send messages to Messaging Service (Publisher)
\item Task B: subscribe for messages, e.g. filtered by topic, from the
	Messaging Service
\end{itemize}
\end{itemize}
\end{block}
\end{frame}

\begin{frame}
\frametitle{Real-time CORBA Extensions}
\begin{center}
\includegraphics[height=0.7\textheight]{images/rtcorbaext.jpg}
\end{center}
\begin{raggedright}
%\scriptsize OMG Real-time CORBA speccification
\end{raggedright}
\end{frame}

\subsubsection{ACE/TAO Framework}
\begin{frame}
\frametitle{ACE/TAO Software Architecture}
\begin{center}
\includegraphics[height=0.7\textheight]{images/ace.jpg}
\end{center}
\begin{raggedright}
\scriptsize http://cs.wustl.edu/schmidt/ACE
\end{raggedright}
\end{frame}

\begin{frame}
\frametitle{TAO, Real-time CORBA Distribution}
\begin{block}{Facts}
\begin{itemize}
\item c++ implementation
\item based on ACE (operating system independent)
\item RTCORBA specification implemented
\item open source software
\item commercial support
\item widely used
\end{itemize}
\end{block}
\end{frame}

\subsection{Conclusion}
\begin{frame}
\frametitle{Conclusion}
\begin{itemize}
\item many frameworks available
\item different kind of abstraction
\item special frameworks for special problems
\item which framework is best for my problem?
\item is it helpful to use multiple frameworks?
\end{itemize}
\end{frame}

\input{tailpres}
