@Test public void testAppendJSON() { MessageBuilder messageBuilder = new MessageBuilder(); messageBuilder.appendJson("[test]"); //noinspection SpellCheckingInspection assertEquals("The message text should match", "§rtest§r", messageBuilder.getClassicMessage()); }
@Override public Void call() throws Exception { try { LOG.debug("Batched SyncRequestProcessor gets started."); MessageTuple lastReq = null; // Number of transactions batched so far. int batchCount = 0; while (true) { MessageTuple req; if (lastReq == null) { req = this.proposalQueue.take(); } else { req = this.proposalQueue.poll(); if (req == null || batchCount == maxBatchSize || req == MessageTuple.REQUEST_OF_DEATH) { // Sync to disk and send ACK to leader. this.log.sync(); Zxid zxid = MessageBuilder.fromProtoZxid(lastReq.getMessage().getProposal().getZxid()); sendAck(lastReq.getServerId(), zxid); batchCount = 0; } } if (req == MessageTuple.REQUEST_OF_DEATH) { break; } if (req == null) { lastReq = null; continue; } if (req.getMessage().getType() == MessageType.PROPOSAL) { // It's PROPOSAL, sync to disk. Message msg = req.getMessage(); Transaction txn = MessageBuilder.fromProposal(msg.getProposal()); // TODO : avoid this? ByteBuffer body = txn.getBody().asReadOnlyBuffer(); LOG.debug("Syncing transaction {} to disk.", txn.getZxid()); this.log.append(txn); batchCount++; lastReq = req; if (txn.getType() == ProposalType.COP_VALUE) { // If it's COP, we should also update cluster_config file. ClusterConfiguration cnf = ClusterConfiguration.fromByteBuffer(body, this.serverId); persistence.setLastSeenConfig(cnf); // If it's COP, we shouldn't batch it, send ACK immediatly. sendAck(req.getServerId(), txn.getZxid()); batchCount = 0; lastReq = null; } } } } catch (Exception e) { LOG.error("Caught an exception in SyncProposalProcessor", e); throw e; } LOG.debug("SyncProposalProcessor has been shut down."); return null; }
public String toJson() { HashMap<String, Object> payload = new HashMap<String, Object>(); payload.put(MEETING_ID, meetingId); payload.put(REQUESTER_ID, requesterId); payload.put(POLL, poll); java.util.HashMap<String, Object> header = MessageBuilder.buildHeader(POLL_STARTED, VERSION, null); return MessageBuilder.buildJson(header, payload); }
public String toJson() { HashMap<String, Object> payload = new HashMap<String, Object>(); payload.put(Constants.MEETING_ID, meetingId); payload.put(Constants.PRESENTATION_ID, presentationId); payload.put(Constants.SHARE, share); java.util.HashMap<String, Object> header = MessageBuilder.buildHeader(SHARE_PRESENTATION, VERSION, null); return MessageBuilder.buildJson(header, payload); }
public String toJson() { HashMap<String, Object> payload = new HashMap<String, Object>(); payload.put(Constants.MEETING_ID, meetingId); payload.put(Constants.USER_ID, userId); payload.put(Constants.RECORDING, recording); java.util.HashMap<String, Object> header = MessageBuilder.buildHeader(Get_RECORDING_STATUS_REPLY, VERSION, null); return MessageBuilder.buildJson(header, payload); }
public static DbgpMessage create(Node node) { if (node == null) { return null; } String rootName = node.getNodeName(); if (INIT.equals(rootName)) { return new InitMessage(node); } else if (STREAM.equals(rootName)) { return MessageBuilder.createStream(node); } else if (RESPONSE.equals(rootName)) { return MessageBuilder.createResponse(node); } return null; }
public static void main(String[] args) { MessageBuilder builder1 = new ConcreteBuilder1(); MessageBuilder builder2 = new ConcreteBuilder2(); Director director = new Director(builder1); director.constructMessage(); Message msg1 = builder1.retrieveMessage(); System.out.println(msg1); System.out.println(); director.setBuilder(builder2); director.constructMessage(); Message msg2 = builder2.retrieveMessage(); System.out.println(msg2); }
@Override public MessageModelCoreTO sayHelloCore(MessageCoreTO coreMessageParameterObject) { log.info("CoreService getMessage start"); MessageBuilder messageBuilder = messageBuilderFactory.createMessageBuilder( coreMessageParameterObject.getMessage1(), coreMessageParameterObject.getMessage2()); log.info("CoreService getMessage try to send mail"); SimpleMailTO mail = SimpleMailTO.getValidInstance( "*****@*****.**", "*****@*****.**", "mail Test", "Mail Test Body"); mailService.sendSimpleMail(mail); log.info("CoreService getMessage send mail"); return messageBuilder.build(); }
public void started(AbstractBuild build) { String changes = getChanges(build); CauseAction cause = build.getAction(CauseAction.class); if (changes != null) { notifyStart(build, changes); } else if (cause != null) { MessageBuilder message = new MessageBuilder(notifier, build); message.append(cause.getShortDescription()); notifyStart(build, message.toString()); } else { notifyStart(build, getBuildStatusMessage(build)); } }
String getChanges(AbstractBuild r) { if (!r.hasChangeSetComputed()) { logger.info("No change set computed..."); return null; } ChangeLogSet changeSet = r.getChangeSet(); List<Entry> entries = new LinkedList<Entry>(); Set<AffectedFile> files = new HashSet<AffectedFile>(); for (Object o : changeSet.getItems()) { Entry entry = (Entry) o; logger.info("Entry " + o); entries.add(entry); files.addAll(entry.getAffectedFiles()); } if (entries.isEmpty()) { logger.info("Empty change..."); return null; } Set<String> authors = new HashSet<String>(); for (Entry entry : entries) { authors.add(entry.getAuthor().getDisplayName()); } MessageBuilder message = new MessageBuilder(notifier, r); message.append("Started by changes from "); message.append(StringUtils.join(authors, ", ")); message.append(" ("); message.append(files.size()); message.append(" file(s) changed)"); return message.toString(); }
private void specificView(ViewContext ctx, JSONObject data, boolean showBullets) throws JSONException { ctx.respond( "#module %s #plain module -- %s", data.getString("name"), data.getString("description")); final String[] examples = data.getStringArray("examples"); if (examples == null || examples.length == 0) { ctx.respond("No examples available"); } else { ctx.respond("Examples:"); for (String example : examples) { final MessageBuilder builder = ctx.buildResponse(); builder.add(showBullets ? MessageBuilder.BULLET + " " : " "); for (String piece : example.split(" ")) { if (piece.length() > 1 && piece.startsWith(".")) { builder.add("#command %s ", new Object[] {piece}); } else if (piece.length() > 2 && piece.startsWith("_") && piece.endsWith("_")) { builder.add("#argument %s ", new Object[] {piece.substring(1, piece.length() - 1)}); } else { builder.add("%s ", new Object[] {piece}); } } builder.send(); } } }
@Test public void testMessageBuilder() { List<MessageComponent> messageComponents = new ArrayList<>(); messageComponents.add(new MessageComponent()); assertNotNull( "The message builder should not be null", new MessageBuilder(messageComponents.get(0))); assertNotNull("The message builder should not be null", new MessageBuilder(messageComponents)); assertNotNull( "The message builder should not be null", new MessageBuilder("", MessageColor.BLUE)); assertNotNull( "The message builder should not be null", new MessageBuilder("", new ChatColor[] {ChatColor.BOLD})); assertNotNull("The message builder should not be null", MessageBuilder.fromJson("")); }
public static boolean sendMessage( MessageBuilder builder, final WebsiteProperties websiteProperties) { try { Properties props = System.getProperties(); // props.put( "mail.debug", "true" ); props.put("mail.smtp.host", websiteProperties.getMailHost()); props.put("mail.smtp.user", websiteProperties.getMailUser()); props.put("password", websiteProperties.getMailPassword()); props.put("mail.smtp.auth", "true"); props.put( "mail.smtp.starttls.enable", "true"); // necessary if you use cu or google, otherwise you receive an error: Session session = Session.getInstance( props, new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication( websiteProperties.getMailUser(), websiteProperties.getMailPassword()); } }); Message message = builder.build(session); // build the message Transport.send(message); return true; // success = true } catch (MessagingException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return false; // success = false }
/** * parse a MIME message, calling the builder methods that correspond to the message's header * fields and body parts. */ OutboundMessageIF parse(MIMEMessage msg) { this.msg = msg; builder = MessageBuilder.getInstance(getDestination()); MessagePart hdr = nextHeader(); while (hdr != null) { if (hdr.getName().equalsIgnoreCase("to")) builder.to((String) hdr.getValue()); else if (hdr.getName().equalsIgnoreCase("from")) builder.from((String) hdr.getValue()); // ... hdr = nextHeader(); } // while hdr MessagePart bdy = nextBodyPart(); while (bdy != null) { if (bdy.getName().equals("text/plain")) builder.plainText((String) bdy.getValue()); // ... else if (bdy.getName().equals("image/jpeg")) builder.jpegImage((Image) bdy.getValue()); // ... bdy = nextHeader(); } // while bdy return builder.getOutboundMsg(); } // parse(MIMEMessage)
/** * Creates a new Message instance from a {@link MessageBuilder}. * * @param messageBuilder The {@link MessageBuilder} used to build the message. */ public Message(@NotNull MessageBuilder messageBuilder) { this(messageBuilder.getJsonMessageAsList()); }
/** * Creates a new Message instance from a {@link MessageBuilder}. * * @param messageBuilder The {@link MessageBuilder} used to build the message. * @param method The method used to display the message on the players client. */ public Message(@NotNull MessageBuilder messageBuilder, @NotNull SendMethod method) { this(messageBuilder.getJsonMessageAsList(), method); }
String getBuildStatusMessage(AbstractBuild r) { MessageBuilder message = new MessageBuilder(notifier, r); message.appendStatusMessage(); message.appendDuration(); return message.toString(); }
/** * Queues a message to be written to the modem. * * @param message the message to be written. */ public void queueMessage(MessageBuilder message) { String data = message.build(); logger.debug("Queueing message {}.", data); executor.execute(new Message(data.getBytes())); }
@Override public <T> MessageBuilder<T> withPayload(T payload) { return MessageBuilder.withPayload(payload); }
@Override public <T> MessageBuilder<T> fromMessage(Message<T> message) { return MessageBuilder.fromMessage(message); }
@Test @SuppressWarnings("SpellCheckingInspection") public void testTootltips() { MessageBuilder messageBuilder = new MessageBuilder("Test"); messageBuilder.achievementTooltip(Achievement.BREED_COW); assertTrue("The tooltip should match", messageBuilder.getJson().contains("BREED_COW")); messageBuilder.statisticTooltip(Statistic.BANNER_CLEANED); assertTrue("The tooltip should match", messageBuilder.getJson().contains("BANNER_CLEANED")); messageBuilder.statisticTooltip(Statistic.BREAK_ITEM, Material.ANVIL); assertTrue("The tooltip should match", messageBuilder.getJson().contains("ANVIL")); messageBuilder.statisticTooltip(Statistic.ENTITY_KILLED_BY, EntityType.ARROW); assertTrue("The tooltip should match", messageBuilder.getJson().contains("ARROW")); messageBuilder.itemTooltip(new ItemStack(Material.ACTIVATOR_RAIL, 10)); assertTrue("The tooltip should match", messageBuilder.getJson().contains("ACTIVATOR_RAIL")); }
void sendAck(String source, Zxid ackZxid) { Message ack = MessageBuilder.buildAck(ackZxid); this.transport.send(source, ack); }