Search in sources :

Example 56 with Singleton

use of com.google.inject.Singleton in project joynr by bmwcarit.

the class EhcacheModule method getCacheManager.

@Provides
@Singleton
CacheManager getCacheManager(@Named(BounceProxyEhcacheAdapter.PROPERTY_BP_CACHE_CONFIGURATION) String cacheConfigFileName) {
    log.info("Using ehcache config file: {}", cacheConfigFileName);
    URL cacheConfigFileUrl = getClass().getResource("/" + cacheConfigFileName);
    if (cacheConfigFileUrl == null) {
        log.error("No resource with filename found on classpath: {}. Using default CacheManager", cacheConfigFileName);
        return CacheManager.newInstance();
    } else {
        return CacheManager.newInstance(cacheConfigFileUrl);
    }
}
Also used : URL(java.net.URL) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 57 with Singleton

use of com.google.inject.Singleton in project incubator-myriad by apache.

the class MesosModule method providesSchedulerDriver.

@Provides
@Singleton
SchedulerDriver providesSchedulerDriver(MyriadScheduler scheduler, MyriadConfiguration cfg, SchedulerState schedulerState) {
    Builder frameworkInfoBuilder = FrameworkInfo.newBuilder().setUser("").setName(cfg.getFrameworkName()).setCheckpoint(cfg.isCheckpoint()).setFailoverTimeout(cfg.getFrameworkFailoverTimeout());
    frameworkInfoBuilder.setRole(cfg.getFrameworkRole());
    Optional<FrameworkID> optFrameId = schedulerState.getFrameworkID();
    if (optFrameId.isPresent()) {
        FrameworkID frameworkId = optFrameId.get();
        LOGGER.info("Attempting to re-register with frameworkId: {}", frameworkId.getValue());
        frameworkInfoBuilder.setId(frameworkId);
    }
    String mesosAuthenticationPrincipal = cfg.getMesosAuthenticationPrincipal();
    String mesosAuthenticationSecretFilename = cfg.getMesosAuthenticationSecretFilename();
    if (StringUtils.isNotEmpty(mesosAuthenticationPrincipal)) {
        frameworkInfoBuilder.setPrincipal(mesosAuthenticationPrincipal);
        Credential.Builder credentialBuilder = Credential.newBuilder();
        credentialBuilder.setPrincipal(mesosAuthenticationPrincipal);
        if (StringUtils.isNotEmpty(mesosAuthenticationSecretFilename)) {
            try {
                credentialBuilder.setSecretBytes(ByteString.readFrom(new FileInputStream(mesosAuthenticationSecretFilename)));
            } catch (FileNotFoundException ex) {
                LOGGER.error("Mesos authentication secret file was not found", ex);
                throw new RuntimeException(ex);
            } catch (IOException ex) {
                LOGGER.error("Error reading Mesos authentication secret file", ex);
                throw new RuntimeException(ex);
            }
        }
        return new MesosSchedulerDriver(scheduler, frameworkInfoBuilder.build(), cfg.getMesosMaster(), credentialBuilder.build());
    } else {
        return new MesosSchedulerDriver(scheduler, frameworkInfoBuilder.build(), cfg.getMesosMaster());
    }
}
Also used : Credential(org.apache.mesos.Protos.Credential) Builder(org.apache.mesos.Protos.FrameworkInfo.Builder) FileNotFoundException(java.io.FileNotFoundException) FrameworkID(org.apache.mesos.Protos.FrameworkID) ByteString(com.google.protobuf.ByteString) IOException(java.io.IOException) MesosSchedulerDriver(org.apache.mesos.MesosSchedulerDriver) FileInputStream(java.io.FileInputStream) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 58 with Singleton

use of com.google.inject.Singleton in project ovirt-engine by oVirt.

the class StorageModule method getStorageDataCenterListProvider.

// Searchable Detail Models
@Provides
@Singleton
public SearchableDetailModelProvider<StorageDomain, StorageListModel, StorageDataCenterListModel> getStorageDataCenterListProvider(EventBus eventBus, Provider<DefaultConfirmationPopupPresenterWidget> defaultConfirmPopupProvider, final Provider<FindSingleDcPopupPresenterWidget> singlePopupProvider, final Provider<FindMultiDcPopupPresenterWidget> multiPopupProvider, final Provider<RemoveConfirmationPopupPresenterWidget> removeConfirmPopupProvider, final Provider<StorageListModel> mainModelProvider, final Provider<StorageDataCenterListModel> modelProvider) {
    SearchableDetailTabModelProvider<StorageDomain, StorageListModel, StorageDataCenterListModel> result = new SearchableDetailTabModelProvider<StorageDomain, StorageListModel, StorageDataCenterListModel>(eventBus, defaultConfirmPopupProvider) {

        @Override
        public AbstractModelBoundPopupPresenterWidget<? extends Model, ?> getModelPopup(StorageDataCenterListModel source, UICommand lastExecutedCommand, Model windowModel) {
            StorageDataCenterListModel model = getModel();
            if (lastExecutedCommand == model.getAttachCommand()) {
                if (model.getAttachMultiple()) {
                    return multiPopupProvider.get();
                } else {
                    return singlePopupProvider.get();
                }
            } else {
                return super.getModelPopup(source, lastExecutedCommand, windowModel);
            }
        }

        @Override
        public AbstractModelBoundPopupPresenterWidget<? extends ConfirmationModel, ?> getConfirmModelPopup(StorageDataCenterListModel source, UICommand lastExecutedCommand) {
            if (lastExecutedCommand == getModel().getDetachCommand() || lastExecutedCommand.getName().equals("OnAttach")) {
                // $NON-NLS-1$) {
                return removeConfirmPopupProvider.get();
            } else if (lastExecutedCommand == getModel().getMaintenanceCommand() || lastExecutedCommand.getName().equals("OnMaintenance")) {
                // $NON-NLS-1$) {
                return removeConfirmPopupProvider.get();
            } else {
                return super.getConfirmModelPopup(source, lastExecutedCommand);
            }
        }
    };
    result.setMainModelProvider(mainModelProvider);
    result.setModelProvider(modelProvider);
    return result;
}
Also used : StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) StorageListModel(org.ovirt.engine.ui.uicommonweb.models.storage.StorageListModel) StorageDataCenterListModel(org.ovirt.engine.ui.uicommonweb.models.storage.StorageDataCenterListModel) TemplateBackupModel(org.ovirt.engine.ui.uicommonweb.models.storage.TemplateBackupModel) StorageTemplateListModel(org.ovirt.engine.ui.uicommonweb.models.storage.StorageTemplateListModel) DiskProfileListModel(org.ovirt.engine.ui.uicommonweb.models.profiles.DiskProfileListModel) StorageDataCenterListModel(org.ovirt.engine.ui.uicommonweb.models.storage.StorageDataCenterListModel) StorageSnapshotListModel(org.ovirt.engine.ui.uicommonweb.models.storage.StorageSnapshotListModel) StorageRegisterDiskListModel(org.ovirt.engine.ui.uicommonweb.models.storage.StorageRegisterDiskListModel) StorageRegisterVmListModel(org.ovirt.engine.ui.uicommonweb.models.storage.StorageRegisterVmListModel) StorageVmListModel(org.ovirt.engine.ui.uicommonweb.models.storage.StorageVmListModel) StorageRegisterTemplateListModel(org.ovirt.engine.ui.uicommonweb.models.storage.StorageRegisterTemplateListModel) StorageEventListModel(org.ovirt.engine.ui.uicommonweb.models.storage.StorageEventListModel) StorageLeaseListModel(org.ovirt.engine.ui.uicommonweb.models.storage.StorageLeaseListModel) VmBackupModel(org.ovirt.engine.ui.uicommonweb.models.storage.VmBackupModel) PermissionListModel(org.ovirt.engine.ui.uicommonweb.models.configure.PermissionListModel) StorageRegisterDiskImageListModel(org.ovirt.engine.ui.uicommonweb.models.storage.StorageRegisterDiskImageListModel) StorageDiskListModel(org.ovirt.engine.ui.uicommonweb.models.storage.StorageDiskListModel) StorageListModel(org.ovirt.engine.ui.uicommonweb.models.storage.StorageListModel) ConfirmationModel(org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel) Model(org.ovirt.engine.ui.uicommonweb.models.Model) StorageDRListModel(org.ovirt.engine.ui.uicommonweb.models.storage.StorageDRListModel) StorageIsoListModel(org.ovirt.engine.ui.uicommonweb.models.storage.StorageIsoListModel) ImportCloneModel(org.ovirt.engine.ui.uicommonweb.models.storage.ImportCloneModel) StorageGeneralModel(org.ovirt.engine.ui.uicommonweb.models.storage.StorageGeneralModel) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) SearchableDetailTabModelProvider(org.ovirt.engine.ui.common.uicommon.model.SearchableDetailTabModelProvider) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 59 with Singleton

use of com.google.inject.Singleton in project ovirt-engine by oVirt.

the class TemplateModule method getTemplateListProvider.

// Main List Model
@Provides
@Singleton
public MainModelProvider<VmTemplate, TemplateListModel> getTemplateListProvider(EventBus eventBus, final Provider<DefaultConfirmationPopupPresenterWidget> defaultConfirmPopupProvider, final Provider<TemplateEditPresenterWidget> popupProvider, final Provider<VmExportPopupPresenterWidget> exportPopupProvider, final Provider<VmPopupPresenterWidget> createVmPopupProvider, final Provider<RemoveConfirmationPopupPresenterWidget> removeConfirmPopupProvider, final Provider<TemplateListModel> modelProvider, final Provider<VmDiskPopupPresenterWidget> newDiskPopupProvider, final Provider<SingleSelectionVmDiskAttachPopupPresenterWidget> attachDiskPopupProvider, final Provider<VmHighPerformanceConfigurationPresenterWidget> highPerformanceConfigurationProvider) {
    MainViewModelProvider<VmTemplate, TemplateListModel> result = new MainViewModelProvider<VmTemplate, TemplateListModel>(eventBus, defaultConfirmPopupProvider) {

        @Override
        public AbstractModelBoundPopupPresenterWidget<? extends Model, ?> getModelPopup(TemplateListModel source, UICommand lastExecutedCommand, Model windowModel) {
            TemplateListModel model = getModel();
            if (lastExecutedCommand == model.getEditCommand()) {
                return popupProvider.get();
            } else if (lastExecutedCommand == getModel().getExportCommand()) {
                return exportPopupProvider.get();
            } else if (lastExecutedCommand == getModel().getCreateVmFromTemplateCommand()) {
                if (windowModel instanceof AttachDiskModel) {
                    return attachDiskPopupProvider.get();
                } else if ((windowModel instanceof NewDiskModel) || (windowModel instanceof EditDiskModel)) {
                    return newDiskPopupProvider.get();
                } else {
                    return createVmPopupProvider.get();
                }
            } else {
                return super.getModelPopup(source, lastExecutedCommand, windowModel);
            }
        }

        @Override
        public AbstractModelBoundPopupPresenterWidget<? extends ConfirmationModel, ?> getConfirmModelPopup(TemplateListModel source, UICommand lastExecutedCommand) {
            if (lastExecutedCommand == getModel().getRemoveCommand()) {
                return removeConfirmPopupProvider.get();
            } else if ("OnSave".equals(lastExecutedCommand.getName())) {
                // $NON-NLS-1$
                return defaultConfirmPopupProvider.get();
            } else if (// $NON-NLS-1$
            "OnSaveVm".equals(lastExecutedCommand.getName()) && source.getConfirmWindow() instanceof VmHighPerformanceConfigurationModel) {
                return highPerformanceConfigurationProvider.get();
            } else {
                return super.getConfirmModelPopup(source, lastExecutedCommand);
            }
        }
    };
    result.setModelProvider(modelProvider);
    return result;
}
Also used : MainViewModelProvider(org.ovirt.engine.ui.common.uicommon.model.MainViewModelProvider) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) EditDiskModel(org.ovirt.engine.ui.uicommonweb.models.vms.EditDiskModel) NewDiskModel(org.ovirt.engine.ui.uicommonweb.models.vms.NewDiskModel) TemplateInterfaceListModel(org.ovirt.engine.ui.uicommonweb.models.templates.TemplateInterfaceListModel) TemplateEventListModel(org.ovirt.engine.ui.uicommonweb.models.templates.TemplateEventListModel) AttachDiskModel(org.ovirt.engine.ui.uicommonweb.models.vms.AttachDiskModel) NewDiskModel(org.ovirt.engine.ui.uicommonweb.models.vms.NewDiskModel) TemplateListModel(org.ovirt.engine.ui.uicommonweb.models.templates.TemplateListModel) VmHighPerformanceConfigurationModel(org.ovirt.engine.ui.uicommonweb.models.vms.VmHighPerformanceConfigurationModel) TemplateVmListModel(org.ovirt.engine.ui.uicommonweb.models.templates.TemplateVmListModel) TemplateStorageListModel(org.ovirt.engine.ui.uicommonweb.models.templates.TemplateStorageListModel) PermissionListModel(org.ovirt.engine.ui.uicommonweb.models.configure.PermissionListModel) EditDiskModel(org.ovirt.engine.ui.uicommonweb.models.vms.EditDiskModel) ConfirmationModel(org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel) Model(org.ovirt.engine.ui.uicommonweb.models.Model) TemplateDiskListModel(org.ovirt.engine.ui.uicommonweb.models.templates.TemplateDiskListModel) DiskModel(org.ovirt.engine.ui.uicommonweb.models.vms.DiskModel) TemplateGeneralModel(org.ovirt.engine.ui.uicommonweb.models.templates.TemplateGeneralModel) VmHighPerformanceConfigurationModel(org.ovirt.engine.ui.uicommonweb.models.vms.VmHighPerformanceConfigurationModel) TemplateListModel(org.ovirt.engine.ui.uicommonweb.models.templates.TemplateListModel) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) AttachDiskModel(org.ovirt.engine.ui.uicommonweb.models.vms.AttachDiskModel) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 60 with Singleton

use of com.google.inject.Singleton in project ovirt-engine by oVirt.

the class VirtualMachineModule method getVmInterfaceListProvider.

@Provides
@Singleton
public SearchableDetailModelProvider<VmNetworkInterface, VmListModel<Void>, VmInterfaceListModel> getVmInterfaceListProvider(EventBus eventBus, Provider<DefaultConfirmationPopupPresenterWidget> defaultConfirmPopupProvider, final Provider<VmInterfacePopupPresenterWidget> popupProvider, final Provider<RemoveConfirmationPopupPresenterWidget> removeConfirmPopupProvider, final Provider<VmListModel<Void>> mainModelProvider, final Provider<VmInterfaceListModel> modelProvider) {
    SearchableDetailTabModelProvider<VmNetworkInterface, VmListModel<Void>, VmInterfaceListModel> result = new SearchableDetailTabModelProvider<VmNetworkInterface, VmListModel<Void>, VmInterfaceListModel>(eventBus, defaultConfirmPopupProvider) {

        @Override
        public AbstractModelBoundPopupPresenterWidget<? extends Model, ?> getModelPopup(VmInterfaceListModel source, UICommand lastExecutedCommand, Model windowModel) {
            VmInterfaceListModel model = getModel();
            if (lastExecutedCommand == model.getNewCommand() || lastExecutedCommand == model.getEditCommand()) {
                return popupProvider.get();
            } else {
                return super.getModelPopup(source, lastExecutedCommand, windowModel);
            }
        }

        @Override
        public AbstractModelBoundPopupPresenterWidget<? extends ConfirmationModel, ?> getConfirmModelPopup(VmInterfaceListModel source, UICommand lastExecutedCommand) {
            if (lastExecutedCommand == getModel().getRemoveCommand()) {
                return removeConfirmPopupProvider.get();
            } else {
                return super.getConfirmModelPopup(source, lastExecutedCommand);
            }
        }
    };
    result.setMainModelProvider(mainModelProvider);
    result.setModelProvider(modelProvider);
    return result;
}
Also used : VmListModel(org.ovirt.engine.ui.uicommonweb.models.vms.VmListModel) VmInterfaceListModel(org.ovirt.engine.ui.uicommonweb.models.vms.VmInterfaceListModel) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) VmListModel(org.ovirt.engine.ui.uicommonweb.models.vms.VmListModel) VmDevicesListModel(org.ovirt.engine.ui.uicommonweb.models.vms.VmDevicesListModel) VmAffinityGroupListModel(org.ovirt.engine.ui.uicommonweb.models.configure.scheduling.affinity_groups.list.VmAffinityGroupListModel) VmErrataCountModel(org.ovirt.engine.ui.uicommonweb.models.VmErrataCountModel) VmGuestInfoModel(org.ovirt.engine.ui.uicommonweb.models.vms.VmGuestInfoModel) AttachDiskModel(org.ovirt.engine.ui.uicommonweb.models.vms.AttachDiskModel) NewDiskModel(org.ovirt.engine.ui.uicommonweb.models.vms.NewDiskModel) VmInterfaceListModel(org.ovirt.engine.ui.uicommonweb.models.vms.VmInterfaceListModel) ImportVmsModel(org.ovirt.engine.ui.uicommonweb.models.vms.ImportVmsModel) VmHighPerformanceConfigurationModel(org.ovirt.engine.ui.uicommonweb.models.vms.VmHighPerformanceConfigurationModel) VncInfoModel(org.ovirt.engine.ui.uicommonweb.models.vms.VncInfoModel) ImportVmFromExportDomainModel(org.ovirt.engine.ui.uicommonweb.models.vms.ImportVmFromExportDomainModel) VmDiskListModel(org.ovirt.engine.ui.uicommonweb.models.vms.VmDiskListModel) VmAffinityLabelListModel(org.ovirt.engine.ui.uicommonweb.models.configure.labels.list.VmAffinityLabelListModel) VmAppListModel(org.ovirt.engine.ui.uicommonweb.models.vms.VmAppListModel) PermissionListModel(org.ovirt.engine.ui.uicommonweb.models.configure.PermissionListModel) EditDiskModel(org.ovirt.engine.ui.uicommonweb.models.vms.EditDiskModel) ConfirmationModel(org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel) VmSnapshotListModel(org.ovirt.engine.ui.uicommonweb.models.vms.VmSnapshotListModel) VmEventListModel(org.ovirt.engine.ui.uicommonweb.models.vms.VmEventListModel) VmGeneralModel(org.ovirt.engine.ui.uicommonweb.models.vms.VmGeneralModel) Model(org.ovirt.engine.ui.uicommonweb.models.Model) VmGuestContainerListModel(org.ovirt.engine.ui.uicommonweb.models.vms.VmGuestContainerListModel) VmHostDeviceListModel(org.ovirt.engine.ui.uicommonweb.models.vms.hostdev.VmHostDeviceListModel) ImportVmFromExternalProviderModel(org.ovirt.engine.ui.uicommonweb.models.vms.ImportVmFromExternalProviderModel) VmNextRunConfigurationModel(org.ovirt.engine.ui.uicommonweb.models.vms.VmNextRunConfigurationModel) VmErrataListModel(org.ovirt.engine.ui.uicommonweb.models.VmErrataListModel) VmImportGeneralModel(org.ovirt.engine.ui.uicommonweb.models.vms.VmImportGeneralModel) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) SearchableDetailTabModelProvider(org.ovirt.engine.ui.common.uicommon.model.SearchableDetailTabModelProvider) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Aggregations

Singleton (com.google.inject.Singleton)81 Provides (com.google.inject.Provides)78 AbstractModule (com.google.inject.AbstractModule)8 Injector (com.google.inject.Injector)8 Named (com.google.inject.name.Named)7 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)7 ConfirmationModel (org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel)7 Model (org.ovirt.engine.ui.uicommonweb.models.Model)7 File (java.io.File)5 IOException (java.io.IOException)5 SearchableDetailTabModelProvider (org.ovirt.engine.ui.common.uicommon.model.SearchableDetailTabModelProvider)5 PermissionListModel (org.ovirt.engine.ui.uicommonweb.models.configure.PermissionListModel)5 DataSourceFactory (io.dropwizard.db.DataSourceFactory)4 ManagedDataSource (io.dropwizard.db.ManagedDataSource)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 InetSocketAddress (java.net.InetSocketAddress)3 SocketAddress (java.net.SocketAddress)3 Properties (java.util.Properties)3 Test (org.junit.Test)3 ConfigModule (co.cask.cdap.common.guice.ConfigModule)2