/** Shut down communication with the autosampler. */ public void disconnect() { if (m_reader != null) { m_reader.quit(); m_reader.interrupt(); } if (m_sender != null) { m_sender.quit(); m_sender.interrupt(); } if (m_statusPoller != null) { m_statusPoller.quit(); m_statusPoller.interrupt(); } if (m_CryoSocket != null) { m_CryoSocket.disconnect(); m_CryoSocket = null; } }
@Test public void testBestellung_1() { System.out.println("testBestellung_1 von niklaus am 11.6.2014"); createTestBestellungHorizontal(); System.out.println("testBestellung_2"); System.out.println(order.toString()); CoreHub.globalCfg.set(Constants.CFG_ROSE_CLIENT_NUMBER, "999993"); CoreHub.globalCfg.set(Constants.CFG_ROSE_USERNAME, "elexis"); CoreHub.globalCfg.set(Constants.CFG_ROSE_PASSWORD, "elexis"); Sender sender = null; System.out.println("testBestellung_3"); try { sender = new Sender(); sender.store(order); } catch (XChangeException e) { System.out.println(e.toString()); // loading the class failed; do nothing fail("loading Sender class failed:" + e.toString()); } try { if (sender != null) { sender.finalizeExport(); // System.out.println("elem ist: "+XChangeElement.) } } catch (XChangeException e) { // loading the class failed; do nothing fail("finalizeExport failed:" + e.toString()); } System.out.println("testBestellung_4"); assertTrue(true); // finished sending }
/** Disconnect Android from USB */ public void disconnect() { if (m_connected) { m_connected = false; } if (m_handler != null) { m_handler.stop(); } if (m_sender != null && m_sender.is_active()) { if (m_sender.stop()) { Log.d(LinkManager.class.getSimpleName(), "There was non-send message !"); // TODO : autre traitement ? } } if (m_receiver != null && m_receiver.is_active()) { if (m_receiver.stop()) { Log.d(LinkManager.class.getSimpleName(), "All the message were not handled !"); // TODO : autre traitement ? } } if (m_device != null) { /* try { m_device.close(); } catch (IOException e) { }*/ m_device = null; } m_listener.UsbStop(); }
@SuppressWarnings("serial") private void testLinker(int addressCount, int messageCount) { server.setMaxConnections(addressCount); Linker linker = new Linker(); linker.start(reactor); for (int i : range(addressCount)) { for (int j : range(messageCount)) { Sender snd = linker.sender(server.address(i), null); assertEquals("sender per address", i + 1, linker.sendersSize()); final int fi = i, fj = j; snd.send(dict("i", fi, "j", fj)); } } linker.close(); reactor.run(); HashMap<Integer, ArrayList<Map<?, ?>>> by_addr = new HashMap<>(); for (int i : range(addressCount)) { by_addr.put(i, new ArrayList<Map<?, ?>>()); } ArrayList<Map<?, ?>> messagesDicts = sink.getMessagesDicts(); for (Map<?, ?> m : messagesDicts) { assertNotNull("did not receive a dict", m); by_addr.get(m.get("i")).add(m); } for (int i : range(addressCount)) { ArrayList<Map<?, ?>> actual = by_addr.get(i); ArrayList<Map<?, ?>> expected = new ArrayList<>(messageCount); for (int j : range(messageCount)) { expected.add(dict("i", i, "j", j)); } assertEquals(String.format("Messages for address %d", i), expected, actual); } assertEquals("total messages", addressCount * messageCount, messagesDicts.size()); }
public static void main(String args[]) { Builder builder = new Builder(); list = builder.produceMailSender(10); for (Sender s : list) { s.send(); } }
public void killAll() { for (Sender s : senders) { if (s.getState() == MulticastStream.State.ACTIVE) { s.deactivate(); } } this.stfe.shutdown(); }
@Test public void testProduceSender() { System.out.println("producing sms sender"); Sender s1 = sf.produceSender("sms"); s1.send(); System.out.println("producing mail sender"); Sender s2 = sf.produceSender("mail"); s2.send(); System.out.println("error producing type"); sf.produceSender("hello"); }
public static void main(String[] args) { // 1.普通工厂模式 // Sender sender = (new SendFactory()).produce("mail"); // 2.多个工厂方法模式 3.静态工厂方法模式 // Sender sender = SendFactory.produceMail(); // 抽象工厂方法 Provider provider = new SendMailFactory(); Sender sender = provider.produce(); sender.Send(); }
/* (non-Javadoc) * @see android.widget.AdapterView.OnItemClickListener#onItemClick(android.widget.AdapterView, android.view.View, int, long) * the only clickable we listen to is the Compose button */ public void onItemClick(android.widget.AdapterView<?> parent, View view, int position, long id) { Sender sender = new Sender(this); StringBuilder sb = new StringBuilder(); appendBodyText(position, sb); sender.send( new HappyEmail( _prefs.getString("etpHerEmail1", ""), _prefs.getString(Util.SUBJECT_RECENT_PREF + (position + 1), ""), sb.toString())); }
void sendMessages() throws Exception { if (num_threads > 1 && num_msgs % num_threads != 0) { System.err.println( "num_msgs (" + num_msgs + " ) has to be divisible by num_threads (" + num_threads + ")"); return; } System.out.println( "sending " + num_msgs + " messages (" + Util.printBytes(msg_size) + ") to " + remote + ": oob=" + oob + ", " + num_threads + " sender thread(s)"); ByteBuffer buf = ByteBuffer.allocate(Global.BYTE_SIZE + Global.LONG_SIZE).put(START).putLong(num_msgs); Message msg = new Message(null, buf.array()); // msg.writeTo(output); ExposedByteArrayOutputStream out_stream = new ExposedByteArrayOutputStream((int) (msg.size())); ExposedDataOutputStream dos = new ExposedDataOutputStream(out_stream); byte flags = 0; dos.writeShort(Version.version); // write the version if (msg.getDest() == null) flags += (byte) 2; dos.writeByte(flags); msg.writeTo(dos); Buffer buffer = new Buffer(out_stream.getRawBuffer(), 0, out_stream.size()); output_lock.lock(); // need to sync if we have more than 1 sender try { // msg.writeTo(output); output.writeInt(buffer.getLength()); output.write(buffer.getBuf(), buffer.getOffset(), buffer.getLength()); } finally { output_lock.unlock(); } int msgs_per_sender = num_msgs / num_threads; Sender[] senders = new Sender[num_threads]; for (int i = 0; i < senders.length; i++) senders[i] = new Sender(msgs_per_sender, msg_size, num_msgs / 10); for (Sender sender : senders) sender.start(); for (Sender sender : senders) sender.join(); output.flush(); System.out.println("done sending " + num_msgs + " to " + remote); }
/** * Send a command to the cryobay. * * @param commandMessage The string to send to the cryobay. * @return True if there is a connection to the cryobay */ public synchronized boolean sendToCryoBay(String command) { if (m_sender == null) { m_sender = new Sender(null, m_retries, this); m_sender.start(); } if (isConnected()) { m_sender.addCommand(command); // TODO: (Java 5) Release semaphore here // m_sender.interrupt(); // Wake up the run() method return true; } else { return false; } }
public ExecutionCourseSender(ExecutionCourse executionCourse) { super(); setCourse(Objects.requireNonNull(executionCourse)); setFromAddress(Sender.getNoreplyMail()); addReplyTos(new ExecutionCourseReplyTo()); addReplyTos(new CurrentUserReplyTo()); setMembers(TeacherGroup.get(executionCourse)); final String labelECTeachers = BundleUtil.getString( Bundle.SITE, "label.org.fenixedu.academic.domain.accessControl.ExecutionCourseTeachersGroupWithName", new String[] {executionCourse.getNome()}); final String labelECStudents = BundleUtil.getString( Bundle.SITE, "label.org.fenixedu.academic.domain.accessControl.ExecutionCourseStudentsGroupWithName", new String[] {executionCourse.getNome()}); final String labelECResponsibleTeachers = BundleUtil.getString( Bundle.SITE, "label.org.fenixedu.academic.domain.accessControl.ExecutionCourseResponsibleTeachersGroupWithName", new String[] {executionCourse.getNome()}); // fixed recipients addRecipients(new Recipient(labelECTeachers, TeacherGroup.get(executionCourse))); addRecipients(new Recipient(labelECStudents, StudentGroup.get(executionCourse))); addRecipients( new Recipient( labelECResponsibleTeachers, TeacherResponsibleOfExecutionCourseGroup.get(executionCourse))); setFromName(createFromName()); }
public void send(Message message) throws CommunicationException { try { m_delegateSender.send(message); } finally { shutdown(); } }
public void sendTaggedData(int tag, int flags, byte[] bytes, SendCallback cb) { try { sender.enqueue(new SendEntry(tag, flags, bytes, this, cb)); } catch (InterruptedException e) { throw new RuntimeException(e); } }
private void testSender(int count) { ArrayList<String> expected = new ArrayList<String>(count); for (int i = 0; i < count; i++) { expected.add(template.render(i)); } server.setMaxConnections(1); Sender snd = Sender.Builder().withTarget(server.address()).create(); reactor.getHandler().add(snd); snd.start(reactor); for (String msg : expected) { snd.send(msg); } snd.close(); reactor.run(); assertEquals("messages received", expected, sink.getMessages()); }
/** * @param data Guaranteed to be non null * @param offset * @param length */ public void send(byte[] data, int offset, int length) throws Exception { if (sender != null) { byte[] copy = new byte[length]; System.arraycopy(data, offset, copy, 0, length); sender.addToQueue(new Buffer(copy, 0, length)); } else _send(data, offset, length, true, true); }
@Override public void lifecycleEvent(LifecycleEvent event) { if (Lifecycle.PERIODIC_EVENT.equals(event.getType())) { if (sender == null) { if (proxyList == null) sender = new MultiCastSender(); else sender = new TcpSender(); } /* Read busy and ready */ if (coll == null) { try { coll = new CollectedInfo(host, port); this.port = coll.getPort(); this.host = coll.getHost(); } catch (Exception ex) { log.error("Unable to initialize info collection: " + ex); coll = null; return; } } /* Start or restart sender */ try { sender.init(this); } catch (Exception ex) { log.error("Unable to initialize Sender: " + ex); sender = null; return; } /* refresh the connector information and send it */ try { coll.refresh(); } catch (Exception ex) { log.error("Unable to collect load information: " + ex); coll = null; return; } String output = "v=1&ready=" + coll.getReady() + "&busy=" + coll.getBusy() + "&port=" + port; try { sender.send(output); } catch (Exception ex) { log.error("Unable to send colllected load information: " + ex); } } }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); sender = new Sender(); sender.start(); attachEventHandlers(); }
@Override public boolean onCommand(Sender sender, String[] args) { if (!sender.isAdmin()) { sender.sendMessageServer("Tu n'a pas la permisions"); return true; } if (args.length >= 1) { User u = User.getUser(args[0]); if (u != null && !u.equals(sender) && !u.isAdmin()) { u.kick(); return true; } } return false; }
public void stop() { try { flush(); } catch (Exception ex) { logger.warn("Unable to flush before stop", ex); } sender.stop(); }
public void start() { if (receiver != null) receiver.stop(); receiver = new Receiver(server.factory).start(); if (isSenderUsed()) { if (sender != null) sender.stop(); sender = new Sender(server.factory, server.sendQueueSize()).start(); } }
public void send(int chan, byte[] data) { try { // System.out.println("data " + new String(data)); TransportPacket tp; boolean last = false; boolean envoieTotal = false; int pointeurData = 0; short numSeq = 0; int actualLenght; while (!envoieTotal) { byte[] dataToSend; if (last || ((Protocol.HEADER_LENGTH_DATA + data.length) < Protocol.MAX_PACKET_SIZE)) { dataToSend = new byte[Protocol.HEADER_LENGTH_DATA + (data.length - pointeurData)]; last = true; envoieTotal = true; } else dataToSend = new byte[Protocol.MAX_PACKET_SIZE]; // System.out.println("datatosend 1 : " +dataToSend.length); actualLenght = dataToSend.length - Protocol.HEADER_LENGTH_DATA; byte[] fragData = new byte[dataToSend.length - Protocol.HEADER_LENGTH_DATA]; System.arraycopy(data, pointeurData, fragData, 0, fragData.length); tp = new TransportPacket(data.length, actualLenght, chan, last, numSeq, fragData); dataToSend = tp.build(); // System.out.println("datatosend 2 : " +dataToSend.length); /* System.out.println("header " + header.length); System.out.println("data " + dataToSend.length); System.arraycopy(header, 0, dataToSend, 0, header.length); System.arraycopy(data, pointeurData, dataToSend, header.length, Math.min((dataToSend.length - header.length), (data.length - pointeurData))); * System.out.println(" actual lenght ? " + actualLenght); * System.out.println("data ? "+ new String(data) + " LA taille : " + data.length); * System.out.println("nouveau pointeur ? "+ pointeurData); * System.out.println("toSend ? "+ new String(dataToSend)); * System.out.println("taille ? "+ dataToSend.length); * System.out.println("tailleheader ? "+ header.length); // */ // System.out.println("Paquet " + numSeq); pointeurData = pointeurData + actualLenght; numSeq++; if ((data.length - pointeurData) <= (Protocol.MAX_PACKET_SIZE - Protocol.HEADER_LENGTH_DATA)) { last = true; } sender.send(dataToSend); } } catch (NullPointerException e) { System.out.println("Ce channel n'est pas index�"); e.printStackTrace(); } }
/** Model startuje i uruchamia wszystkie potrzebne moduły. */ public void load() { if (self == null) { outQueue.add(new ProgramClosingEvent()); throw new NullPointerException("Self contact nie może być null!"); } server.start(); multicast.start(); sender.start(); }
@Override public void call(List<MethodCall<Object>> methodCalls) { if (methodCalls.size() > 0) { String returnAddress = methodCalls.get(0).returnAddress(); @SuppressWarnings("unchecked") List<Message<Object>> methods = (List<Message<Object>>) (Object) methodCalls; sender.send(returnAddress, encoder.encodeAsString(methods)); } }
@After public void tearDown() { channel.close(); audioMixer.stop(); oobMixer.stop(); udpManager.stop(); mediaScheduler.stop(); scheduler.stop(); sender.close(); }
/** * @param data Guaranteed to be non null * @param offset * @param length */ private void send(byte[] data, int offset, int length) throws Exception { if (isSenderUsed()) { // we need to copy the byte[] buffer here because the original buffer might get // changed meanwhile byte[] tmp = new byte[length]; System.arraycopy(data, offset, tmp, 0, length); sender.addToQueue(tmp); } else { _send(data, offset, length, true); } }
/** * Does the work for processReply. * * @see #processReply */ private void processReplyInEventThread(String what, boolean value) { // Messages.postDebug("cryocmd", "CryoSocketControl.processReply(" // + what + ", " + value + ")"); if (debug) System.out.println("CryoSocketControl.gotReply: " + what); if (what != null) { m_sender.gotReply(value); processStatus(what, value); } }
public void run() { try { final Sender m_sender = createSender(); final int n = s_random.nextInt(10); for (int i = 0; i < n; ++i) { m_sender.send(new SimpleMessage(1)); sleep(s_random.nextInt(30)); } synchronized (Sender.class) { s_numberOfMessages += n; } m_sender.shutdown(); } catch (Exception e) { e.printStackTrace(); } }
public boolean sendAlert(AlertChannel channel, AlertMessageEntity message) { String channelName = channel.getName(); try { boolean result = true; String str = "nosend"; if (m_configManager.isSendMachine()) { Sender sender = m_senders.get(channelName); result = sender.send(message); str = String.valueOf(result); } Cat.logEvent("Channel:" + channelName, message.getType() + ":" + str, Event.SUCCESS, null); return result; } catch (Exception e) { Cat.logError(e); return false; } }
private void testSampler(final int count, float frequency) { server.setMaxConnections(1); final ArrayList<String> expected = new ArrayList<String>(count); Timeout gen = new Timeout() { Tag tag = new SimpleTag(0); int sent = 0; @Override public void onSample(DatawireEvent e) { String body = template.render(sent); expected.add(body); Message message = Message.Factory.create(); message.setBody(new AmqpValue(body)); DatawireUtils.send(e.getLink(), tag, message); sent += 1; if (sent >= count) { e.getLink().close(); cancel(); } } }; Sender snd = Sender.Builder() .withTarget(server.address()) .withHandlers(new Sampler(gen, frequency)) .create(); reactor.getHandler().add(snd); gen.setTimeout(reactor, 2000); snd.start(reactor); reactor.run(); assertTrue("Sampling timed out", gen.isCancelled()); assertEquals("Expected messages", expected, sink.getMessages()); }