static void appendMessages(Tpp tpp, Collection<MessageBatchWithRawData> batches) throws Exception { List<MessagePriority> msgs = new ArrayList<>(); for (MessageBatchWithRawData batch : batches) { List<PartialDecodedMessage> pdmsgs = batch.getMessages(); for (PartialDecodedMessage pdmsg : pdmsgs) { MessagePriority msg = new MessagePriority(); msg.setAttributes(pdmsg.readDurableProperties()); msg.setCreationDate(new Date(pdmsg.getBornTime())); msg.setPartition(tpp.getPartition()); msg.setPayload(pdmsg.readBody()); msg.setPriority(tpp.isPriority() ? 0 : 1); msg.setProducerId(0); msg.setProducerIp(""); msg.setRefKey(pdmsg.getKey()); msg.setTopic(tpp.getTopic()); msg.setCodecType(pdmsg.getBodyCodecType()); msgs.add(msg); } } long start = System.currentTimeMillis(); MessagePriority[] array = msgs.toArray(new MessagePriority[msgs.size()]); System.out.println("ToArray: " + (System.currentTimeMillis() - start)); start = System.currentTimeMillis(); PlexusComponentLocator.lookup(MessagePriorityDao.class).insert(array); System.out.println("Insert: " + (System.currentTimeMillis() - start)); }
private Topic findTopic(String topicName) { try { return PlexusComponentLocator.lookup(MetaService.class).refreshMeta().findTopic(topicName); } catch (Exception e) { log.error("Find topic failed.", e); return null; } }
@Override public void ConsumeAsync(int maxThread, Boolean autoAck) { this.isAutoAck = autoAck; Engine engine = PlexusComponentLocator.lookup(Engine.class); maxThread = maxThread <= 0 ? 1 : maxThread; for (int i = 0; i < maxThread; i++) { engine.start(new Subscriber(topic, groupId, new InnerConsumer())); } }
@Path("/storage/") @Singleton @Produces(MediaType.APPLICATION_JSON) public class TopicStorageResource { private TopicService service = PlexusComponentLocator.lookup(TopicService.class); // /storage/size?ds=1&table=5 /** * Why wrapper primitive value into map? or Why not just return Integer or String on these REST * API? * * <p>Answer: front-end use ng-resource to request these API, And $resource want them to return * object. $resource can't parse primitive type. (ref to: * https://github.com/angular/angular.js/issues/4314) By Jacob, 6.23.2015. */ @GET @Path("size") public Map<String, Object> getSize( @QueryParam("ds") String datasource, @QueryParam("table") String table) { checkDatasourceNotNull(datasource); Map<String, Object> result = new HashMap<>(); try { if (null == table) { result.put("size", service.queryStorageSize(datasource)); } else { result.put("size", service.queryStorageSize(datasource, table)); } } catch (StorageHandleErrorException e) { result.put("error", e.getMessage()); } return result; } @GET @Path("tables") public List<StorageTable> getTables(@QueryParam("ds") String datasource) throws StorageHandleErrorException { checkDatasourceNotNull(datasource); // todo: 返回异常到前端的$http.error()中去。 return service.queryStorageTables(datasource); } @GET @Path("partitions") public List<StoragePartition> getTablesPartition( @QueryParam("ds") String datasource, @QueryParam("table") String table) throws StorageHandleErrorException { checkDatasourceNotNull(datasource); return service.queryStorageTablePartitions(datasource, table); } @GET @Path("addp") public Map<String, String> addPartitionStorage( @QueryParam("ds") String datasource, @QueryParam("table") String table, @QueryParam("span") Integer span) { checkDSAndTable(datasource, table); Map<String, String> result = new HashMap<>(); boolean isSuccess = false; try { service.addPartitionStorage(datasource, table, span); isSuccess = true; } catch (StorageHandleErrorException e) { result.put("error", e.getMessage()); } result.put("result", isSuccess ? "success" : "fail"); return result; } @GET @Path("deletep") public Map<String, String> deletePartitionStorage( @QueryParam("ds") String datasource, @QueryParam("table") String table) { checkDSAndTable(datasource, table); Map<String, String> result = new HashMap<>(); boolean isSuccess = false; try { service.delPartitionStorage(datasource, table); isSuccess = true; } catch (StorageHandleErrorException e) { result.put("error", e.getMessage()); } result.put("result", isSuccess ? "success" : "fail"); return result; } private void checkDSAndTable(String datasource, String table) { checkDatasourceNotNull(datasource); checkTableNotNull(table); } private void checkDatasourceNotNull(String datasource) { if (null == datasource) { throw new RestException("datasource is null!"); } } private void checkTableNotNull(String table) { if (null == table) { throw new RestException("table is null!"); } } }
public String getEnvironment() { return PlexusComponentLocator.lookup(ClientEnvironment.class).getEnv().name(); }
@JsonIgnore @JSONField(serialize = false) public long getRemainingTime() { SystemClockService systemClockService = PlexusComponentLocator.lookup(SystemClockService.class); return m_expireTime.get() - systemClockService.now(); }