Created
December 21, 2011 10:57
-
-
Save nskvortsov/1505610 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
senderThread = new Thread() { | |
run () { | |
while (!runSender) { | |
int id = nextIdFromQueue(); | |
if (id == null) { | |
Thread.currentThread().sleep(50) | |
continue; | |
} else { | |
byte[] data = RMS.read(id); | |
RMS.remove(id); // данные прочитали, убили из хранилища. | |
for (int i=0; i<data.length) { | |
reading.add(new Point(data[i]); | |
if (readyToSend(reading) { | |
try { | |
sendReading(reading); // синхронная отправка | |
clearAndReinit(reading); | |
} catch (Exception e) { | |
// stop() всей работы с девайсом: мы не осилили отправить сообщение совсем. | |
} | |
} | |
} | |
} | |
} | |
}; | |
senderThread.start(); | |
public static final List QUEUE = new LinkedList(); | |
public volatile booleand runSender = true; | |
public Integer nextIdFromQueue() { | |
if (QUEUE.size() > 0) { | |
synchronized(QUEUE) { | |
final Integer first = (Integer)QUEUE.get(0); | |
QUEUE.remove(0); | |
return first; | |
} | |
} else { | |
return null; | |
} | |
} | |
public void putIdToQueue(Integer nextId) { | |
synchronized(QUEUE) { | |
QUEUE.add(nextId); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment