org.apache.wicket.util.time.Duration Java Examples

The following examples show how to use org.apache.wicket.util.time.Duration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractTableTreePage.java    From JPPF with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param viewType the type of tree this page holds.
 * @param namePrefix the name prefix for the toolbar and table tree.
 */
public AbstractTableTreePage(final TreeViewType viewType, final String namePrefix) {
  this.viewType = viewType;
  this.namePrefix = namePrefix;
  add(getOrCreateToolbar());
  final TableTreeData data = JPPFWebSession.get().getTableTreeData(viewType);
  treeModel = data.getModel();
  selectionHandler = data.getSelectionHandler();
  tableTree = createTableTree("jppf." + namePrefix + ".visible.columns");
  tableTree.add(new WindowsTheme()); // adds windows-style handles on nodes with children
  final int interval = JPPFWebConsoleApplication.get().getRefreshInterval();
  refreshTimer = new AjaxSelfUpdatingTimerBehavior(Duration.seconds(interval));
  tableTree.add(refreshTimer);
  tableTree.addUpdateTarget(toolbar);
  data.selectionChanged(selectionHandler);
  if (debugEnabled) log.debug("table tree created");
  add(tableTree);
  if (debugEnabled) log.debug("table tree added to page");
}
 
Example #2
Source File: TypeParser.java    From wicket-spring-boot with Apache License 2.0 6 votes vote down vote up
public static Duration parse(Long time, DurationUnit durationUnit){
	switch(durationUnit){
	case DAYS:
		return Duration.days(time);
	case HOURS:
		return Duration.hours(time);
	case MILLISECONDS:
		return Duration.milliseconds(time);
	case MINUTES:
		return Duration.minutes(time);
	case SECONDS:
		return Duration.seconds(time);
	}
	
	throw new WicketSpringBootException("Could not parse time with duration unit " + time + " " + durationUnit);
}
 
Example #3
Source File: InfoUtil.java    From nextreports-server with Apache License 2.0 6 votes vote down vote up
public static List<Info> getGeneralJVMInfo() {
	List<Info> infos = new ArrayList<Info>();
	
	RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
	infos.add(new Info("uptime", "" + Duration.milliseconds(runtimeBean.getUptime()).toString()));
	infos.add(new Info("name", runtimeBean.getName()));
	infos.add(new Info("pid", runtimeBean.getName().split("@")[0]));
	
	OperatingSystemMXBean systemBean = ManagementFactory.getOperatingSystemMXBean();
	infos.add(new Info("os name", "" + systemBean.getName()));
	infos.add(new Info("os version", "" + systemBean.getVersion()));
	infos.add(new Info("system load average", "" + systemBean.getSystemLoadAverage()));
	infos.add(new Info("available processors", "" + systemBean.getAvailableProcessors()));

	ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
	infos.add(new Info("thread count",  "" + threadBean.getThreadCount()));
	infos.add(new Info("peak thread count",  "" + threadBean.getPeakThreadCount()));
	
	MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
	infos.add(new Info("heap memory used",  FileUtils.byteCountToDisplaySize(memoryBean.getHeapMemoryUsage().getUsed())));
	infos.add(new Info("non-heap memory used",  FileUtils.byteCountToDisplaySize(memoryBean.getNonHeapMemoryUsage().getUsed())));
	
	return infos;
}
 
Example #4
Source File: MonitorPanel.java    From nextreports-server with Apache License 2.0 6 votes vote down vote up
public MonitorPanel(String id) {
	super(id);

	jobsTable = createJobsTable(new ReportJobInfoDataProvider());
	jobsTable.setOutputMarkupId(true);
	add(jobsTable);

	schedulerJobsTable = createSchedulerJobsTable(new ActiveSchedulerJobDataProvider());
	schedulerJobsTable.setOutputMarkupId(true);
	add(schedulerJobsTable);

	RunHistoryPanel runHistoryPanel = new RunHistoryPanel("runHistoryPanel", null);
	runHistoryTable = runHistoryPanel.getRunHistoryTable();
	runHistoryTable.setOutputMarkupId(true);
	add(runHistoryPanel);

	Settings settings = storageService.getSettings();
	int updateInterval = settings.getUpdateInterval();

	if (updateInterval > 0) {
		jobsTable.add(new AjaxSelfUpdatingTimerBehavior(Duration.seconds(updateInterval)));
		schedulerJobsTable.add(new AjaxSelfUpdatingTimerBehavior(Duration.seconds(updateInterval)));
		runHistoryTable.add(new AjaxSelfUpdatingTimerBehavior(Duration.seconds(updateInterval)));
	}
}
 
Example #5
Source File: ExportPanel.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
private Component buildCustomDownloadLink() {
	return new DownloadLink("downloadCustomGradebook", new LoadableDetachableModel<File>() {
		private static final long serialVersionUID = 1L;

		@Override
		protected File load() {
			return buildFile(true);
		}

	}, buildFileName(true)).setCacheDuration(Duration.NONE).setDeleteAfterDownload(true).setOutputMarkupId(true);
}
 
Example #6
Source File: ExportPanel.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
private Component buildCustomDownloadLink() {
	return new DownloadLink("downloadCustomGradebook", new LoadableDetachableModel<File>() {
		private static final long serialVersionUID = 1L;

		@Override
		protected File load() {
			return buildFile(true);
		}

	}, buildFileName(true)).setCacheDuration(Duration.NONE).setDeleteAfterDownload(true).setOutputMarkupId(true);
}
 
Example #7
Source File: DashboardColumnPanel.java    From nextreports-server with Apache License 2.0 5 votes vote down vote up
private WidgetPanel createWidgetPanel(String id, Widget widget, WidgetModel widgetModel) {
	WidgetPanel widgetPanel = new WidgetPanel(id, widgetModel);		
	int refreshTime = WidgetUtil.getRefreshTime(dashboardService, widget);
       if (refreshTime > 0) {
           widgetPanel.add(new AjaxSelfUpdatingTimerBehavior(Duration.seconds(refreshTime)));                    
       }        
       return widgetPanel;
}
 
Example #8
Source File: HomePage.java    From nextreports-server with Apache License 2.0 5 votes vote down vote up
@Override
protected void onInitialize() {
	super.onInitialize();

       // obtain a reference to a Push service implementation
       final IPushService pushService = TimerPushService.get();       
       ((TimerPushService)pushService).setDefaultPollingInterval(Duration.seconds(storageService.getSettings().getPollingInterval()));
       

       // instantiate push event handler
       IPushEventHandler<Message> handler = new AbstractPushEventHandler<Message>() {

           private static final long serialVersionUID = 1L;

           @Override
           public void onEvent(AjaxRequestTarget target, Message event, IPushNode<Message> node, IPushEventContext<Message> context) {
               int messageType = event.isError() ?	JGrowlAjaxBehavior.ERROR_STICKY : JGrowlAjaxBehavior.INFO_STICKY;
               getSession().getFeedbackMessages().add(new FeedbackMessage(null, event.getText(), messageType));
               target.add(growlLabel);

               boolean autoOpen = storageService.getSettings().isAutoOpen();
               String reportsUrl = storageService.getSettings().getReportsUrl();
               if (autoOpen && StringUtils.contains(event.getText(), reportsUrl)) {
                   growlBehavior.setAfterOpenJavaScript(getJGrowlAfterOpenJavaScript());
               }
           }

       };

       // install push node into this panel
       final IPushNode<Message> pushNode = pushService.installNode(this, handler);

       // push report result
   	initPushReportResult(pushService, pushNode);

       // push survey
   	initPushSurvey(pushService, pushNode);
}
 
Example #9
Source File: Start.java    From etcd-viewer with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    int timeout = (int) Duration.ONE_HOUR.getMilliseconds();

    System.setProperty(WICKET_CFG, CfgType.development.toString());

    Server server = new Server();

    ServerConnector connector = new ServerConnector(server);

    // Set some timeout options to make debugging easier.
    connector.setIdleTimeout(timeout);
    connector.setSoLingerTime(-1);
    connector.setPort(8080);
    server.addConnector(connector);

    Resource keystore = Resource.newClassPathResource("/keystore");
    if (keystore != null && keystore.exists()) {
        // if a keystore for a SSL certificate is available, start a SSL
        // connector on port 8443.
        // By default, the quickstart comes with a Apache Wicket Quickstart
        // Certificate that expires about half way september 2021. Do not
        // use this certificate anywhere important as the passwords are
        // available in the source.

        SslContextFactory sslContextFactory = new SslContextFactory();
        sslContextFactory.setKeyStoreResource(keystore);
        sslContextFactory.setKeyStorePassword("wicket");
        sslContextFactory.setTrustStoreResource(keystore);
        sslContextFactory.setKeyManagerPassword("wicket");

        // HTTP Configuration
        HttpConfiguration httpConfig = new HttpConfiguration();
        httpConfig.setSecureScheme("https");
        httpConfig.setSecurePort(8443);
        httpConfig.setOutputBufferSize(32768);
        httpConfig.setRequestHeaderSize(8192);
        httpConfig.setResponseHeaderSize(8192);
        httpConfig.setSendServerVersion(true);
        httpConfig.setSendDateHeader(false);

        // SSL HTTP Configuration
        HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
        httpsConfig.addCustomizer(new SecureRequestCustomizer());

        // SSL Connector
        ServerConnector sslConnector = new ServerConnector(server,
                new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
                new HttpConnectionFactory(httpsConfig));
        sslConnector.setPort(8443);

        server.addConnector(sslConnector);

        System.out.println("SSL access to the quickstart has been enabled on port 8443");
        System.out.println("You can access the application using SSL on https://localhost:8443");
        System.out.println();
    }

    WebAppContext bb = new WebAppContext();
    bb.setServer(server);
    bb.setContextPath("/");
    bb.setWar("src/main/webapp");

    // START JMX SERVER
    // MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    // MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
    // server.getContainer().addEventListener(mBeanContainer);
    // mBeanContainer.start();

    server.setHandler(bb);

    try {
        System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
        server.start();
        System.in.read();
        System.out.println(">>> STOPPING EMBEDDED JETTY SERVER");
        server.stop();
        server.join();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}
 
Example #10
Source File: OrienteerWebjarsSettings.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
@Inject(optional=true)
public void setReadFromCacheTimeout(@Named("webjars.readFromCacheTimeout") String readFromCacheTimeout) {
	readFromCacheTimeout(Duration.valueOf(readFromCacheTimeout));
}
 
Example #11
Source File: DashboardPanel.java    From nextreports-server with Apache License 2.0 4 votes vote down vote up
private void changeGlobalSettings(WidgetRuntimeModel runtimeModel, AjaxRequestTarget target) {
	ModalWindow.closeCurrent(target);
			
	WidgetPanelVisitor visitor = new WidgetPanelVisitor();
	visitChildren(WidgetPanel.class, visitor);				
	
	for (WidgetPanel widgetPanel : visitor.getWidgetPanels()) {			
		Widget widget = widgetPanel.getWidget();
		if (widget == null) {
			continue;
		}
		int oldRefreshTime = widget.getRefreshTime();
		WidgetRuntimeModel storedRuntimeModel = ChartUtil.getRuntimeModel(storageService.getSettings(), (EntityWidget)widget, reportService, dataSourceService, true);
		ChartUtil.updateGlobalWidget(widget, storedRuntimeModel, runtimeModel);
		try {				
			dashboardService.modifyWidget(getDashboard().getId(), widget);
		} catch (NotFoundException e) {
			// never happening
			throw new RuntimeException(e);
		}
		int refreshTime = widget.getRefreshTime();
		if (oldRefreshTime != refreshTime) {
			for (Behavior behavior : widgetPanel.getBehaviors()) {
				if (behavior instanceof AjaxSelfUpdatingTimerBehavior) {
					((AjaxSelfUpdatingTimerBehavior) behavior).stop(target);
					// do not remove the behavior : after changing , the
					// event is called one more
					// time on the client so it has to be present ...
				}
			}
			if (refreshTime > 0) {
				widgetPanel.add(new AjaxSelfUpdatingTimerBehavior(Duration.seconds(refreshTime)));
			}
		}
	}
       
	/*
       for (int i = 0; i < getDashboard().getColumnCount(); i++) {
       	target.add(getColumnPanel(i));
       }
       */
	target.add(this);
}