DistributedSystems-Mertz&McCarthy Source:h8p://www.itu.int/en/ITU-D/StaAsAcs/Documents/facts/ICTFactsFigures2015.pdf DistributedSystems-Mertz&McCarthy Source:h8p://www.itu.int/en/ITU-D/StaAsAcs/Documents/facts/ICTFactsFigures2015.pdf DistributedSystems-Mertz&McCarthy Source:h8p://www.comscoredatamine.com/2013/12/amazon-ebay-drive-heavy-app-usage-while-mulA-channel-retailers-rely-on-mobile-web/ DistributedSystems-Mertz&McCarthy Source:h8p://www.comscoredatamine.com/2012/10/mobile-phones-and-tablets-now-account-for-1-in-8-u-s-internet-page-views/ DistributedSystems-Mertz&McCarthy Source:h8p://www.comscore.com/Insights/Blog/Number-of-Mobile-Only-Internet-Users-Now-Exceeds-Desktop-Only-in-the-U.S DistributedSystems-Mertz&McCarthy • Intheforeseeablefuture,mobiledeviceswillbethemost prevalentwaythatpeopleaccesstheInternet,and therefore,distributedsystems. • Learninggoalsfortoday’sclass: 1. Tounderstandmobilephonesascomponentsinadistributed system. • I.e.asadistributedsystemisanapplicaAonorservicebuiltfromasetof heterogeneouscompuAngsystemsthatcommunicatebypassing messages,amobilephoneisoVenoneofthosecompuAngsystems 2. TocreateasimplenaAvemobileapplicaAonthat communicateswithothersystemsinadistributedsystem. (Indoingso,demysAfymobileapps:theyarejustjava programslikeotherswe'vebuilt.) DistributedSystems-Mertz&McCarthy • AnAndroidphoneisjust: – acomputerrunningLinux – withnetworkingcapability – somespecialized hardware(phone,gps camera) – andasoVware stackto support wriAng applicaAons DistributedSystems-Mertz&McCarthy Typeof applica,on Class? Method(s)toimplement? Configura,on informa,onfile? Plain Java ApplicaAon Web ApplicaAon Android ApplicaAon DistributedSystems-Mertz&McCarthy Typeof applica,on Class? Method(s)toimplement? Configura,on informa,onfile? Plain Java ApplicaAon AnyPOJO main() None Web ApplicaAon Android ApplicaAon DistributedSystems-Mertz&McCarthy Typeof applica,on Class? Method(s)toimplement? Configura,on informa,onfile? Plain Java ApplicaAon AnyPOJO main() Web ApplicaAon ExtendH8pServlet doGet(),init(),doPost(),etc. web.xml None Android ApplicaAon DistributedSystems-Mertz&McCarthy • AnAndroidappwitha userinterfaceiscalledan AcAvity • Androidappsextend AcAvityorasubclasssuch asAppCompatAcAvity • AbasicAndroidapp needstoonlyimplement theonCreate()method Source:h8ps://developer.android.com/reference/android/app/AcAvity.html AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="ds.cmu.edu.helloandroid”> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity ds.cmu.edu.helloandroid.MainActivity android:name=".MainActivity" android:label="@string/app_name" android:theme="@style/AppTheme.NoActionBar"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> ds.cmu.edu.helloandroid. MainAcAvity.java publicclassMainAcAvityextendsAppCompatAcAvity{ @Override protectedvoidonCreate(BundlesavedInstanceState){ … DistributedSystems-Mertz&McCarthy Typeof applica,on Class? Method(s)toimplement? Configura,on informa,onfile? Plain Java ApplicaAon AnyPOJO main() Web ApplicaAon ExtendH8pServlet doGet(),init(),doPost(),etc. web.xml Android ApplicaAon ExtendAcAvity (oroneofits subclassessuchas AppCompatAcAvity) onCreate(),onPause(),etc. AndroidManifest.xml None DistributedSystems-Mertz&McCarthy • AnAndroidapp’sUIisdefined – inxmlfiles – withintheresdirectory • TwoediAngmodes: – Design(WYSIWYG) – Text(xml) • Thecompleteresdirectoryiscompiledfromxml intoJavaclassesthatdefinetheRobject • ThereforeR.referstoUIelementsdefinedinthe resdirectory – IfRisundefined,itmeanstheresxmlhasanerror. DistributedSystems-Mertz&McCarthy • SeeTable1at: h8ps://developer.android.com/guide/topics/resources/providing-resources.html • Somekeyelements – layout • HowUIarearranged(linear,grid,etc.) – drawable • Picture(bitmap)files(jpg,png,etc. – menu • ApplicaAonmenus – values • ConstantvaluessuchasstaAcstrings,colors,etc. DistributedSystems-Mertz&McCarthy • TheglobalvariableRreferstoallUIresources. • TosettheUIlayout: – setContentView(R.layout.ac)vity_main); • acAvity_main.xmlwouldbeintheres/layoutdirectory • TofindUIelements,usefindViewById: – Bu8onsubmitBu8on=(Bu8on)findViewById(R.id.submit); • ThiswouldrefertoaBu8onintheUIwiththeID==submit DistributedSystems-Mertz&McCarthy • Roles – User(person1) – UI(person2) • Scenario – UsertossesUIballs,whichtheyprocessquicklyandpass back. – IfoneoftheballsissomethingthattakesalongAme,then subsequentballstossedfromUseraredroppedwhileUI completesit. • Haveyouexperiencedthis? • Howcanyousolveit? DistributedSystems-Mertz&McCarthy • Newrole – Helper(person3) • UIcanpassoffrequeststhatwilltakealongAme toHelper • WhenHelperisfinished,itcanpasstheresults backtoUI – Thescreenisadatastructure,youdon’twantmulAple threadschangingit. – AllUIchangesshouldbedonebytheUIonly DistributedSystems-Mertz&McCarthy Examplecomparisonoflatency,scaledtoifaCPUcycletook1second Event Latency Scaled 1CPUCycle 0.3nsec 1sec MainMemory 120nsec 6min SolidStateDisk 50–150µsec 2–6days RotaAonalDisk 1–10ms 1–12months InternetSFtoNYC 40ms 4years Source:SystemsPerformance:EnterpriseandtheCloud1stEdiAonbyBrendanGregg,ISBN-13:978-0133390094 YoudoNOTwantyourUIwaiAngfor4yearsbeforeitcanrespond toyourscrollgestureorbu8onclick! DistributedSystems-Mertz&McCarthy UI(Main)Thread onPreExecute() onPostExecute() HelperThread doInBackground() DistributedSystems-Mertz&McCarthy • TheAndroiddevelopershaveasetofvideos. • OneishowtogetstartedwithAndroidStudio. – h8ps://www.youtube.com/watch?v=Z98hXV9GmzY DistributedSystems-Mertz&McCarthy