CSE 486/586 Programming Assignment 2, Part A1 Group Messenger 1 solved

$34.99

Original Work ?

Download Details:

  • Name: Group_Messenger_1.zip
  • Type: zip
  • Size: 4.24 MB

Category: You will Instantly receive a download link upon Payment||Click Original Work Button for Custom work

Description

5/5 - (2 votes)

Introduction
This assignment builds on the previous assignment and sets the stage for the next assignment. YouwilldesignagroupmessengerthatcansendmessagestomultipleAVDsandstore received messages in a persistent key-value storage. Like the first assignment, you must followtheseinstructionsexactly. Failure to do so may result in no credit for this assignment. Please read this document in its entirety before you begin. It is long, but that is only because it is complicated and precise. Revisit the instructions regularly as you implement to be sure you’re implementing what is required. This assignment will require you to: • Implement an AndroidContentProvider. • Use file I/O to create a persistent key-value store.
• Manage multiple sockets and multiple client connections.
1 GettingStarted
Successful completion of this assignment will require both the development environment you set up in the first project and the things you learned in implementing the first project. If your development environment for the first project was not 100% operational, please go back and address that now! As in the first project, we are providing a project template for you to get started. This template configures a number of things (such as declaring the appropriate capabilities in the Android Manifest, layingout UI components for automated testing, etc.) on your behalf. It is important that you do not change settings that you do not have to change to complete your project.
2 TheGroupMessengerApp
Thegradedportionofthisprojectisimplementingthegroupmessengerapp. Youwillneed to download the project from GitHub Classroom and open it in Android Studio. You should have received an email containing the GitHub Classroom invitation for this project. If you have not, please contact the teaching staff on Piazza.
1Thisassignmentisbased,withpermission,onanassignmentdevelopedandusedbySteveKoinhisversion of CSE 486/586. Large portions of text are used verbatim from that assignment.
1
Instructions for cloning the project and opening it in Android Studio are the same as for the first project, except that the base repository name is GroupMessenger1. You can find YouTube tutorials detailing the process here. Takesometimetounderstandthetemplatecodeafteryouhavereadtherestofthisdocument. Inparticular,notetheTODOitemsinthethreeJavaclassesGroupMessengerActivity, GroupMessengerProvider,andOnPTestClickListener. YoumaywishtoreferenceyourSimpleMessenger code, as well as the handout code from that project (which, e.g., does filesystem I/O). The requirements for this project are in two parts: implementing an Android content providerandprovidinggroupmessengercommunicationbyimplementingapplication-layer multicast with storage on that provider. They will be detailed here, with their specific requirements and grading criteria.
2.1 WritingaContentProvider The first part of this assignment is implementing aContentProviderthat implements a persistent key-value storage. It takes a string key and a string value, and stores them for later retrieval (even across reboots!). Before you start, please read the following Android documentation on content providers: https://developer.android.com/guide/topics/providers/content-providers.html A typical Android content provider supports basic SQL statements. However, we do not requirethatyoudosoforthiscourse. Yourcontentproviderwillpresentasimplekey-value table abstraction. You may not fully understand all of the details in this list until you have gone back and read the relevant Android documentation. That is OK; read through the requirements first so you know what to look for in the docs!
2.1.1 ContentProviderRequirements 1. Youshouldnotrequireanypermissiontoaccessyourprovider. Thisisveryimportantasit will prevent our testing program from testing your app (and therefore your app from receiving any credit!). The given code takes care of this; as long as you do not change it, you will be fine.
2. Your content provider’s URI should be: content://edu.buffalo.cse.cse486586.groupmessenger1.provider, Any app should be able to access your provider using that URI. To simplify your implementation,yourproviderdoesnotneedtomatchorsupportanyotherURIpattern. This URI is already declared in the given code’s AndroidManifest.xml; again, if you do not change it, you will be fine.
3. Your provider should have two columns.
• Thefirstcolumnshouldbenamed“key”(alllowercase,noquotationmarks). This column is used to store keys.
2
• The second column should be named “value” (all lowercase, no quotation marks). This column is used to store the values associated with keys. • All keys and values stored by your provider should be Java strings. 4. Your provider should implement only insert() and query(). No other operations are necessary.
5. Given that the column names are “key” and “value”, any app should be able to insert a key-value pair as in the following example: ContentValues keyValueToInsert = new ContentValues(); // inserting <“key-to-insert”, “value-to-insert”> keyValueToInsert.put(“key”, “key-to-insert”); keyValueToInsert.put(“value”, “value-to-insert”); // Assume we have already created providerUri with our provider’s URI Uri newUri = getContentResolver().insert(providerUri, keyValueToInsert);
6. If a new value is inserted for a key that already exists, keep only the most recent value. You should not preserve the history of values under the same key. 7. Anyappshouldbeabletoreadakey-valuepairfromyourproviderusingquery(). Since your provider is a simple key-value table, we are not going to follow the Android convention; your provider should answer queries as in this example: Cursor resultCursor = getContentResolver().query( providerUri, // again, assume we already created this null, // no need to support the projection parameter “key-to-read”, // provide the key directly as the selection parameter null, // no need to support the selectionArgs parameter null // no need to support the sortOrder parameter );
8. Your provider should store its key-value pairs using one of the possible data storage options. The details of these options are outlined here: https://developer.android.com/guide/topics/data/data-storage.html You may chose any option you like. However, the easiest option is probably to use internal storage with the key as a file name and the value as the file contents.
After implementing your provider, you can verify whether or not you are meeting the requirements by clicking the “PTest” button provided in the given code. You can look at OnPTestClickListener.javatoseeexactlywhatitisdoing. IfyourproviderdoesnotpassPTest, therewillbenopointsforthisportionoftheassignment.
3
2.2 ImplementingApplication-LayerMulticast The final step is implementing an application-layer multicast messenger (i.e., sending the samemessagetomultipleAVDs). Unlikethefirstproject,nocodeisprovidedtologincoming messages or display them on-screen. However, you may find that doing so is helpful for development and debugging. For this portion of the project, you will need to run five emulators. Recall from project 1 that you can use the providedrun_avds.pyto start the emulators, and that you must use the provided set_redir.py to connect their virtual networks. Please refer to project 1 for more details. Inparticular,wewillbeusingthemulti-portconfigurationasdescribedinproject1. Your app will open one server socket that listens on port 10000, but it will connect to a different port number on the IP address 10.0.2.2 for each emulator, as follows: emulatorserial port emulator-5554 11108 emulator-5556 11112 emulator-5558 11116 emulator-5560 11120 emulator-5562 11124 You can use the code snippet provided in project 1 to help you with this calculation.
2.2.1 MulticastMessengerRequirements 1. Your app must multicast every user-entered message to all app instances, including the one that is sending the message. In the rest of this description, “multicast” always means sending a message to all app instances. It must be able to do this when all five emulators are running simultaneously.
2. Your app should be able to send/receive multiple messages.
3. Your app should be able to handle concurrent messages (that is, multiple messages incoming from multiple apps at the same time).
4. Yourappshouldassignasequencenumbertoeverymessageitreceives. Thesequence numbers should start from 0 and increase by 1 for each received message.
5. Each message should be stored with its sequence number as a key-value pair in your content provider. The key should be the sequence number for the message (as a Java string) and the value the message received.
6. Allappinstancesshouldstoreeverymessageanditscorrespondingsequencenumber individually.
For debugging purposes, you may wish to print the messages to the screen. However, this will not be graded, and the given code does not already do it (as it did in project 1).
4
2.3 Testing We have testing programs to help you see how your code does with our grading criteria. If youfindroughedgesinthetestingprograms,pleasereportitsotheteachingstaffcanfixit. The instructions for using the testing programs are the following:
• Downloadatestingprogramforyourplatform. Ifyourplatformdoesnotrunit,please report it.
1. Windows: Tested on 64-bit Windows 8. 2. Linux: Testedon64-bitDebian9and64-bitUbuntu17.10(seebelowforimportant information about 64-bit systems). 3. Mac OS: Tested on 64-bit Mac OS 10.9 Mavericks.
• Before you run the program, please make sure that you are running all five AVDs. You can usepython run_avd.py 5to start them. • Remember to start the emulator network by runningset_redir.py 10000. • Make sure that you have installed your application on both AVDs!
• Run the testing program from the command line.
• It may issue some warnings or errors during execution. Some of them are normal, some may indicate errors in your program. Examine them to find out!
• The testing program will give you partial and final scores.
As before, you may find that the testing program does not always give full credit even when things seem to be working, due to distributed race conditions. If this is the case, test several times. You may find that debugging and/or the grading script perform in an unexpected way if you run your application multiple times, or if you upgrade it with adb or Android Studio without first uninstalling it. This is because the content provider storage is persistent, so it will be retained even if your application is restarted or upgraded. The content provider storage will be cleared when the app is uninstalled, so you can uninstall it between runs to get around this issue. It can be uninstalled with the following command: adb uninstall edu.buffalo.cse.cse486586.groupmessenger1 Note that you may need to provide the emulator “serial number” (the string listed by adb devices,somethinglikeemulator-5554)withthe-sargumentifyouarerunningmultiple emulators.
5
Notesfor64-bitLinux: Thetestingprogramiscompiled32-bit. Ifyougetanerrorlikethe following, install the 32-bitlibzfor your system: ./simplemessenger-grading.linux: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory OnDebian-baseddistributions,youcanaccomplishthiswiththecommandapt-get install libz1g:i386 as root (you may need to use sudo or su). If apt-get reports an error about the architectureorsaysthepackageisnotfound,youmayneedtoenablemultiarch. Todothis, rundpkg –add-architecture i386as root, then update your APT repositories withapt-get updateas root. Once this is done, you should be able to install the 32-bitlibz. For other distributions you will need to consult your distribution documentation.
3 Submission We use UB CSE autograder for submission. You can find autograder athttps://autograder. cse.buffalo.edu/, and log in with your UBITName and password. Once again, it is critical that you follow everything below exactly. Failure to do so willlead tonocreditforthisassignment. Zip up your entire Android Studio project source tree in a single zip file. Ensure that all of the following are true: 1. You didnot create your zip file from inside theGroupMessenger1directory. 2. Thetop-leveldirectoryinyourzipfileisGroupMessenger1orGroupMessenger1-, and it containsbuild.gradleand all of your sources. 3. Youusedaziputilityandnotanyothercompressionorarchivetool: thismeansno7-Zip, no RAR, no tar, etc.
4 Deadline
This project is due 2018-02-23 11:59:00 AM. This is one hour before our class. This is a firm deadline. If the timestamp on your submission is 11:59:01, it is a late submission. You are expected to attend class on this day!
5 Grading
This assignment is 5% of your final grade. Credit for this assignment will be apportioned as follows:
• 2%: Your content provider behaves correctly.
• 3%: Your messenger app can send, receive, and correctly store messages among all AVDs.
6
Thus, an application that has a working content provider and can multicast messages from any or all AVDs to all other AVDs and store them at the receiver will receive a total of 5%: 2%forhavingaworkingcontentprovider,and3%forworkingmulticastmessagingwith message storage.