[Solved]50 Done Need Help Finish 50 Thanks Import Comabcppstringhandoff Import Comprogramixthread Q37254510
This is 50% done. I need help to finish other 50% . Thanks
import com.abc.pp.stringhandoff.*;
import com.programix.thread.*;
public class StringHandoffImpl implements StringHandoff {
private volatile String message;
private volatile boolean recieverLock = false;
private volatile boolean passLock = false;
private volatile boolean stop = false;
public StringHandoffImpl() {
message = null;
}
@Override
public synchronized void pass(String msg, long msTimeout)
throws InterruptedException,
TimedOutException,
ShutdownException,
IllegalStateException
{
//if message is null change the message
while (message == null)
{
message = msg;
notifyAll();
}
//wait if message is not null
if (msTimeout ==0L)
{
while (message != null)
{
wait();
passLock =false;
}
message = msg; // passLock equaltrue
notifyAll();
}
long endTime = System.currentTimeMillis() + msTimeout;
long msRemaining = msTimeout;
while (message != null && msRemaining >0L)
{
wait (msRemaining);
msRemaining = endTime -System.currentTimeMillis ();
//PassLock equal true
//Stop equal true
}
if (message == null)
{
message = msg;
notifyAll();
}
else
{
throw newTimedOutException();
}
}
@Override
public synchronized void pass(String msg)
throws InterruptedException,
ShutdownException,
IllegalStateException
{
while (message != null)
{
do
{
wait();
}
while (false);
}
}
@Override
public synchronized String receive(long msTimeout)
throws InterruptedException,
TimedOutException,
ShutdownException,
IllegalStateException
{
String receivedMessage;
if (message != null)
{
receivedMessage = message;
message = null;
notifyAll();
return receivedMessage;
}
if (msTimeout == 0L)
{
while (message == null)
{
wait();
}
receivedMessage = message;
message = null;
notifyAll();
return receivedMessage;
}
long endTime = System.currentTimeMillis() +msTimeout;
long msRemaining = msTimeout;
while (message == null && msRemaining > 0L)
{
wait(msRemaining);
msRemaining = endTime -System.currentTimeMillis();
shutdown();
}
if (message != null)
{
receivedMessage = message;
message = null;
notifyAll();
return receivedMessage;
}
throw new TimedOutException();
}
@Override
public synchronized String receive()
throws InterruptedException,
ShutdownException,
IllegalStateException
{
while (message == null)
{
wait();
shutdown();
}
while (!stop)
{
return receive (0);
}
while (message != null)
{
String receivedMessage =message;
receivedMessage = receive(0);
message = null;
notifyAll();
return receivedMessage;
}
throw new ShutdownException();
}
@Override
public synchronized void shutdown()
{
// throw new RuntimeException(“not implemented yet”);
stop = true;
this.notifyAll();
}
@Override
public Object getLockObject() {
return this;
}
}
======================================================
import com.abc.handoff.*;
import com.abc.pp.stringhandoff.*;
import com.abc.pp.stringhandoff.tests.*;
import com.abc.pp.stringhandoff.tests.gui.*;
public class TestStringHandoff {
public static void main(String[] args) {
GuiTestPPStringHandoff.runTests(
“Testing of StringHandoff”,
false,
new StringHandoffFactory() {
@Override
public StringHandoff create() {
return new StringHandoffImpl();
}
});
}
}
Expert Answer
Answer to This is 50% done. I need help to finish other 50% . Thanks import com.abc.pp.stringhandoff.*; import com.programix.threa… . . .
OR

