@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); DataSourceManager sourceManager = new DataSourceManager(this); IDataSource source = new InstagramDataSource(); sourceManager.addSource(source); sourceManager.startFetchingData(); }
@Override public Void call() { ZimbraLog.clearContext(); ZimbraLog.addMboxToContext(getMailboxId()); ZimbraLog.datasource.debug("Running scheduled import for DataSource %s", getDataSourceId()); Mailbox mbox = null; try { // Look up mailbox, account and data source mbox = MailboxManager.getInstance().getMailboxById(getMailboxId()); Account account = mbox.getAccount(); ZimbraLog.addAccountNameToContext(account.getName()); Provisioning prov = Provisioning.getInstance(); DataSource ds = prov.get(account, Key.DataSourceBy.id, getDataSourceId()); if (ds != null) { ZimbraLog.addDataSourceNameToContext(ds.getName()); if (!ds.isEnabled()) { ZimbraLog.datasource.info("DataSource is disabled. Cancelling future tasks."); DataSourceManager.cancelTask(mbox, getDataSourceId()); return null; } // Do the work DataSourceManager.importData(ds); } else { ZimbraLog.datasource.info( "DataSource %s was deleted. Cancelling future tasks.", getDataSourceId()); DataSourceManager.cancelTask(mbox, getDataSourceId()); } } catch (ServiceException e) { ZimbraLog.datasource.warn("Scheduled DataSource import failed.", e); return null; } ZimbraLog.clearContext(); return null; }
/** * Tests Connection of the data source * * @param dsmInfo The meta information of the data source to be tested. */ public boolean testDataSourceConnection(DataSourceMetaInfo dsmInfo) throws DataSourceException { if (log.isDebugEnabled()) { log.debug("Testing connection of data source: " + dsmInfo.getName()); } DataSourceReader dsReader = DataSourceManager.getInstance().getDataSourceReader(dsmInfo.getDefinition().getType()); try { return dsReader.testDataSourceConnection( DataSourceUtils.elementToString( (Element) dsmInfo.getDefinition().getDsXMLConfiguration())); } catch (DataSourceException e) { log.error(e.getMessage(), e); throw e; } }
private Object createDataSourceObject(DataSourceMetaInfo dsmInfo, boolean isUseDataSourceFactory) throws DataSourceException { DataSourceReader dsReader = DataSourceManager.getInstance().getDataSourceReader(dsmInfo.getDefinition().getType()); if (dsReader == null) { throw new DataSourceException( "A data source reader cannot be found for the type '" + dsmInfo.getDefinition().getType() + "'"); } /* sets the current data source's (tenantId + ":" + name) as a thread local value * so it can be read by data source readers */ DataSourceUtils.setCurrentDataSourceId(this.getTenantId() + ":" + dsmInfo.getName()); return dsReader.createDataSource( DataSourceUtils.elementToString((Element) dsmInfo.getDefinition().getDsXMLConfiguration()), isUseDataSourceFactory); }