top of page
gejorcutermtervi

Concurrency State Models And Java Programs Ebook: Software Free Download



Stop dreading concurrency hassles and start reaping the pure power ofmodern multicore hardware. Learn how to avoid shared mutable state andhow to write safe, elegant, explicit synchronization-free programs inJava or other JVM languages including Clojure, JRuby, Groovy, or Scala.


Project GoalsProject 0 asks you to implement what might be described as aclient-server data transfer application. We don't actually needdozens of implementations of data transfer, though, so the real pointis the experience of implementing communication protocols. While youwon't directly re-use your Project 0 code in later projects, you willhave to implement very similar functionality in all of them. This isa chance to explore implementation approaches, because your choicecould have a big effect on how much time those later projects willtake.The operation of communication protocols always involves concurrency,which can be an implementation challenge.Project 0 gives you experience implementing protocols using two approaches:Thread-based. Here we use threads as the sole mechanism toachieve concurrency. The distinguishing feature is that each blockedthread is waiting for only a single thing (e.g., keyboard input, or network input). You probably have had some exposure to threads in previous courses, so this approach should be at least somewhat familiar.Additionally, threads have a long history, and so mature support for themexists in most languages/systems.C/C++, Java, and Python all have completely sane support for threads. (Perldoes not, just in case you were thinking of using it...)Non-blocking IO or asynchronous IO or event-loop based.The basic idea of these alternative approaches is for a single threadto wait on more than one "event source" at a time. For example, athread might wait for either keyboard input or apacket to arrive. Depending on the language/package you use, youmight need to combine this idea with multi-threading (e.g., when usingJava NIO). At the other extreme (e.g., node.js), the entire program issingle-threaded, the major advantage of which is that you have noself-inflicted race conditions.C++ has Boost Asio, an asynchronous IO package.Java has NIO, a non-blocking IO interface.Python has the pyuv package, an event loop package.node.js is a javascript-based language designed around the event-loopmodel. You can use any of those. If you want to use something else, pleasecontact the course instructional staff.To achieve the goals of this project, you must work in pairs. That is, thereare two different developers involved.Project 0 has distinct client and server sides,so there are two distinct pieces of code involved in a full solution.We take advantage of that by dividing the work in this way: ClientServerThread-basedPartner APartner BNot thread-basedPartner BPartner AThis schedule allows you to (a) experience both implementationapproaches, (b) make progress independently of your partner (sinceyour own client and your server should interoperate, even ifimplemented in different languages), and (c) experience having yourcode interoperate with code written by someone else.When you're done, all four combinations of client and server choicesshould work together.P0P MessagesP0P, the Project 0 Protocol, defineswhat messages are sent between the client and server,and how they are encoded. (There is a mail protocol,POP, with a similar-looking name, but the twohave nothing to do with each other.) P0Pis designed to support the Project 0 application.The Project 0 application transfers lines of input fromthe client's stdin to the server, which then prints them onits stdout. Protocol HeadersP0P is much more realistic than the protocolsshown in sections and class, in large part because it defines amessage as a header plus data (rather than just data). Without aheader, you can have only one kind of message, and so can't do simplethings you almost certainly need to do, even if you don't realize it yet.(One example is returning an error indication, for instance, eventhough we don't do that in this project.)Protocols you design should always include headers in message encodings.Protocol SessionsP0P supports the notion of a session.A session is a related sequence of messages coming froma single client.Sessions allow the server to maintain state about each individual client.For instance, the server could, in theory, print out how manymessages it has received in each session, for instance, orit could maintain a shopping cart for each session.(We don't actually implement either of those.)Unlike TCP (which has "connections"),UDP doesn't have any notion related to sessions,so we build them as part of our protocol.Protocol Messages and FormatP0P defines four message types: HELLO,DATA, ALIVE, and GOODBYE.All message encodings include a header. The header is filledwith binary values. The header bytes are the initialbytes of the message. They look like this, with fields sent in orderfrom left to right:magicversioncommandsequence numbersession id16 bits8 bits8 bits32 bits32 bits magic is the value 0xC461 (i.e., decimal 50273, if taken as anunsigned 16-bit integer).An arriving packet whose first two bytes do not match the magic number is silently discarded. version is the value 1. command is 0 for HELLO, 1 for DATA,2 for ALIVE, and 3 for GOODBYE. sequence numbers in messages sent by the client are 0 for the first packet ofthe session, 1 for the next packet, 2 for the one after that, etc.Server sequence numbers simply count up each time the server sends something (in anysession). session id is an arbitrary 32-bit integer. The client choosesits value at random when it starts. Both the client and the server repeatthe session id bits in all messages that are part of that session.Multi-byte values are sent big-endian (which is often called "network byte order").In DATA messages, the header is followed by arbitrary data; the othermessages do not have any data.The receiver can determine the amount of data that was sentby subtracting the known header length from the length of the UDP packet,something the language/package you use will provide some way of obtaining.Only one P0P message may be sent in a single UDP packet,and all P0P messages must fit in a single UDP packet. P0Pitself does not define either maximum or minimum DATA payload sizes.It expects that all reasonable implementations will accept data payloadsthat are considerably larger than a typical single line of typed input.P0P Message ProcessingServerThe server sits in a loop waiting for input from the networkor from stdin. Execution of the serverends when either end of file is detected on stdin orthe input line is "q".When the server quits, it sends GOODBYE messages to allsessions (described shortly) thought to be currently active.When a new packet arrives, the magic number and version are checked.The packet is silently discarded unless those fields match theexpected values.Next, the server examines the session id field. If a session with thatid has already been established, it hands the packet to that session.Otherwise, it creates a new session and hands the packet to it.Server SessionServer sessions operate according to the following FSA diagram:Here transition labels are of the form event / action(s),meaning "when an event of the specified type occurs while in the source state,take the actions specified and transition to the destination state."For instance, the transition HELLO / HELLO; Set timer meansthat when a HELLO message arrives, reply with a HELLOmessage and also set a timer that will raise an event at some later time(unless it is canceled), and then transition to state Receive.Sessions are created (by the server)after receiving a message with a newsession id. The newly created session checks that thisinitial message is a HELLO, and terminates if not.Because the client may never send a GOODBYE,sessions garbage collect themselves by setting an inactivity timer.If no message is received from the client for too long, a GOODBYEis sent and the session terminates.When a DATA message is received from the client, its data payloadis printed to stdout. To give the client a way to determine thatthe session is still up, the session sends an ALIVE message in response to each DATA message it receives.The server session should keep track of the client sequence number it expects next.That is, if it has just processed a packet with sequence number 10, it should rememberthat the next sequence number expected is 11.If the next packet received has a sequence number greater than the expected number,a "lost packet" message should be printed for each missing sequence number.If the next packet's sequence number repeats the last received packet number,a "duplicate packet" message is printed and the packet is discarded.If the next packet's sequence number is less than the last packet's sequence number,we assume it is caused by a protocol error and the session closes: it sends a GOODBYE and transitions to DONE. (Sequence numbers "from the past"can be caused by the Internet delivering packets "out of order." That can occur,and more realistic protocols would want to deal with it more gracefully.)If the server session receives a message for which there is no transition in its current state, it is a protocol error. In that case, it closes.For instance, receivinga HELLO while in Receive is an indication something is seriously wrong, and the only option is to close.Client BehaviorThe client follows the following FSA:Basically, the client sends lines of input to the server.If no packets were ever lost, the client would receive a packet backfor every one it sends: a HELLO in response to a sent HELLO, an ALIVE in response to a DATA,and a GOODBYE in response to a GOODBYE.If no response is received within a timeout,the client takes that as an indication theserver is not running, and so the client terminates. (Note that thisis not a very good assumption as the problem could just be a single droppedpacket. We'll look at how to do a better job of guessing whether or notthe server is really there later in the course.)Session termination normally starts with the client, and involvesa GOODBYE message in each direction. However, if theclient receives a GOODBYE, it believes that the server isgone, no matter what the client's current state, and so it transitionsimmediately to the Closed state.The client shuts down when it detects end of file on stdinand the input is coming from a tty, or when thethe input line is 'q' and input is from a tty.If stdin is connected to a file and eof is reached,the client should try to shut down after all outgoing messageshave been put on the network. (Whether or not you can do that mightdepend on the implementation language/package you're using.)Operational DetailsTo make it easier, or maybe even possible, to run your implementationswe have to have a standard way to invoke your code and to process itsoutput. You must conform exactly the specifications shown here, forboth invocation and output. (Sorry.)InvocationBecause how you launch a program can depend on its implementationlanguage, you may need to write a shell script to conform to these instructions.Whatever you do, when we download your files and issue the commands shownbelow, what is described in the instructions should happen. You shouldcheck, on attu, that it does, before submitting. Server: ./server is the port number the server should bind to. Client: ./client . and give the location of the server.The hostname can be a domain name (e.g., attu1.cs.washington.edu)or an IPv4 address (e.g., 128.208.1.137).Output: Basic Typed InputSuppose you run two client instances, back to back, like this:$ ./client localhost 1234onetwothreeeof$ ./client localhost 1234foobareofHere eof is printed by the client program to indicate that end of file has occurredon stdin. (On Linux, type ctrl-d.) The other lines are what the user typed.The server's output should look like this:$ ./server 1234Waiting on port 1234...0x736f0b1f [0] Session created0x736f0b1f [1] one0x736f0b1f [2] two0x736f0b1f [3] three0x736f0b1f [4] GOODBYE from client.0x736f0b1f Session closed0x545537a9 [0] Session created0x545537a9 [1] foo0x545537a9 [2] bar0x545537a9 [3] GOODBYE from client.0x545537a9 Session closedThe first value on each interesting line is the session id. The number in square brackets is thesequence number of the packet that caused this output line.Output: Input Redirected from FileRedirecting stdin to read from a file makes it possible to offer so much input so fastthat packets are lost. For example:$ ./client localhost 1234 &1 &./client localhost 1234 dual-c2.out 2>&1 &Start the server, redirecting its output to some file, and then execute the script.Doing that should produce server output that shows the two clients are runningconcurrently, as in this example output file.(This output is also non-deterministic.)Execution and Debugging Details The standard Linux program nc can help in early debugging of your implementation.As a client, nc will send input typed at the keyboard to some server.As a server, it will print whatever is sent to it.To start it as a server, issue a command like nc -ul -p 38119.To start it as a client, issue a command likenc -u attu1.cs.washington.edu 38119.nc will never understand the P0P message header, so the most you can get out of it isan easy way to verify that something is being sent or received.wireshark is a tool that can display network packets sent fromor received by your machine. It's a bit difficult to use, and requires privilegesyou cannot get on a CSE machine, but it could be useful if running on your own machine. It is most helpful when nc indicates your codeis sending packets, but there's some problem with the receiver understanding them:wireshark will show you the bits that are put on the wire, and solets you determine whether you have an encoding (sender-side) or decoding (receiver-side)bug.(Note that if you run the client and server on the same machine, wiresharkis unlikely to be able to see any packets traveling between them, even if they arebeing sent.)IP addresses can have "limited scope." For instance, the address127.0.0.1, which corresponds to the name localhost, alwaysmeans the host on which the name is used. Some IP addresses, like 192.168.0.1, are meaningful only on the localnetwork, but are not meaningful when issued on some other network.Finally, some addresses are "global" and can be used anywhere.All of this means you can have various kinds of trouble connecting a client and serverthat are on different machines or different networks.Running two instances on a single machine should always work.Running two instances on two CSE machines should also always work(so long as you avoid the localhost issue).Running one instance at home and one at CSE may or may not work;you might find that you can send packets to CSE from home, for instance, but can'tsend from CSE to your house.attu is actually four machines, whose names are attu1through attu4. If you try to connect your client to your server using thename attu, it will connect at random to any one of the four actualmachines. Use specific host names, rather than attu, to avoid problems.Grading ProcedureFor the testing component of grading, we will run on attu. You should verify that yourprogram can be invoked there in the fashion described above, and that it runssuccessfully.Note that it is very hard to verify that your code will run for us on attu.It may be that it works for you, because you have some environment variable settingyou code relies on, but fails for us, because we don't.We suggest testing by launching a shell that has a minimal environment and running there:$ env -i bash # launch a shell with a minimalm environment$ ./server 1234 # now use that shell..... # ctrl-d to terminate the minimal environment shellTurn in You should turn in a .tar.gz file that, when unpacked, creates the directory structure shown here: The .tar.gz file you submit should have a name that is the lastnames of the two partners and the string "proj0", all separated by hyphens.For example, zhang-zhuo-proj0.tar.gz is a plausible name for the file to be turned in. Expanding that tar file should create a directory whose name is like zhang-zhuo-proj0. That directory should contain subdirectories, named A and B, and a readme.txt file. The first two lines of the readme file should be formatted like this: A: Qiao Zhang B: Danyang ZhuoThose lines may be followed by any number of lines giving additional comments or information. Subdirectories A and B should contain executable files named clientand server, as well as any other files required to run your code. The files in Aare the ones written by partner A, etc. We'll do things like this:$ tar xf zhang-zhuo-proj0.tar.gz$ cd zhang-zhuo-proj0$ cat readme.txt$ cd A$ ./server 5432All those commands should succeed. (They won't if you don't follow the details of this section.)Submit your .tar.gz file to the course dropbox. (There's a linkto the dropbox in the navigation section of all course pages.) Computer Science & Engineering University of Washington Box 352350 Seattle, WA 98195-2350 (206) 543-1695 voice, (206) 543-2969 FAX




Concurrency State Models And Java Programs Ebook: Software Free Download


2ff7e9595c


1 view0 comments

Recent Posts

See All

1st-studio-siberian-mouse-hd-114 Updated

This study deals with a recent collection of stenopodidean and caridean shrimps made in the Abrolhos Archipelago, Bahia, Brazil, in July...

Commentaires


bottom of page