Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.guvnor.structure.backend.config.watch;
 
 import  javax.ejb.Singleton;
 import  javax.ejb.Startup;
 import  javax.ejb.TransactionAttribute;
 
import  org.guvnor.structure.config.SystemRepositoryChangedEvent;
import  org.uberfire.io.IOService;
import  org.uberfire.java.nio.file.Path;
import  org.uberfire.java.nio.file.WatchKey;
import static javax.ejb.TransactionAttributeType.*;
@Singleton
@Startup
@TransactionAttribute(NOT_SUPPORTED)
    @Inject
    @Named("system")
    private org.guvnor.structure.repositories.Repository systemRepository;
    @Inject
    @Named("configIO")
    private IOService ioService;
    // monitor capabilities
    @Inject
    @Repository
    private Event<SystemRepositoryChangedEvent> repoChangedEvent;
    @Inject
    @OrgUnit
    private Event<SystemRepositoryChangedEvent> orgUnitChangedEvent;
    @Inject
    private Event<SystemRepositoryChangedEvent> changedEvent;
    public void setConfigfinal org.guvnor.structure.repositories.Repository systemRepository,
                           final IOService ioService,
                           final Event<SystemRepositoryChangedEvent> repoChangedEvent,
                           final Event<SystemRepositoryChangedEvent> orgUnitChangedEvent,
                           final Event<SystemRepositoryChangedEvent> changedEvent ) {
        this. = systemRepository;
        this. = ioService;
        this. = repoChangedEvent;
        this. = orgUnitChangedEvent;
        this. = changedEvent;
    }
    @Override
    public void executefinal WatchKey watchKey,
                         final long localLastModifiedValue,
                         final AsyncWatchServiceCallback callback ) {
        final long currentValue = getLastModified();
        if ( currentValue > localLastModifiedValue ) {
            callback.callbackcurrentValue );
            // notify first repository
            .fire( new SystemRepositoryChangedEvent() );
            // then org unit
            .fire( new SystemRepositoryChangedEvent() );
            // lastly all others
            .fire( new SystemRepositoryChangedEvent() );
        }
    }
    private long getLastModified() {
        final Path lastModifiedPath = .get( .getUri() ).resolve( . );
        return .getLastModifiedTime( lastModifiedPath ).toMillis();
    }
New to GrepCode? Check out our FAQ X