Example usage for java.util.concurrent ExecutionException getCause

List of usage examples for java.util.concurrent ExecutionException getCause

Introduction

In this page you can find the example usage for java.util.concurrent ExecutionException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:io.hops.security.UsersGroupsCache.java

public int getUserId(String userName) throws IOException {
    if (userName == null) {
        return 0;
    }//  ww w . j a v  a  2s  .  com

    try {
        return userToIdCache.get(userName);
    } catch (ExecutionException e) {
        if (e.getCause() instanceof IOException) {
            throw (IOException) e.getCause();
        } else {
            throw new IOException(e);
        }
    }
}

From source file:io.hops.security.UsersGroupsCache.java

public int getGroupId(String groupName) throws IOException {
    if (groupName == null) {
        return 0;
    }/*  ww  w.  ja  v a2s . c  o  m*/

    try {
        return groupToIdCache.get(groupName);
    } catch (ExecutionException e) {
        if (e.getCause() instanceof IOException) {
            throw (IOException) e.getCause();
        } else {
            throw new IOException(e);
        }
    }
}

From source file:io.hops.security.UsersGroupsCache.java

public String getGroupName(int groupId) throws IOException {
    if (groupId == 0) {
        return null;
    }/*from  ww  w.jav  a  2s.c o  m*/

    try {
        return idToGroupCache.get(groupId);
    } catch (ExecutionException e) {
        if (e.getCause() instanceof IOException) {
            throw (IOException) e.getCause();
        } else {
            throw new IOException(e);
        }
    }
}

From source file:io.hops.security.UsersGroupsCache.java

public void removeGroup(String group) throws IOException {
    assert group != null;

    LOG.debug("Remove group from DB name: " + group);
    try {/*from   w  w  w  . j  a  v  a 2  s .  co  m*/
        int groupID = groupToIdCache.get(group);
        removeGroupFromDB(groupID);
        invCachesGroupRemoved(groupID, group);
    } catch (ExecutionException e) {
        if (e.getCause() instanceof GroupNotFoundException) {
            throw (IOException) e.getCause();
        } else {
            throw new IOException(e);
        }
    }
}

From source file:io.hops.security.UsersGroupsCache.java

public void removeUser(String userName) throws IOException {

    if (userName == null)
        return;//www  .j a v  a2 s  .  co  m

    try {
        int userID = userToIdCache.get(userName);
        LOG.debug("Remove user from DB name: " + userName);
        removeUserFromDB(userID);
        invCacheUserRemoved(userID, userName);
    } catch (ExecutionException e) {
        if (e.getCause() instanceof UserNotFoundException) {
            throw (IOException) e.getCause();
        } else {
            throw new IOException(e);
        }
    }
}

From source file:io.hops.security.UsersGroupsCache.java

public Integer addGroup(String groupName) throws IOException {

    if (groupName == null) {
        return null;
    }/*from  ww w  .j a  v  a 2s.  c  om*/
    try {
        groupToIdCache.get(groupName);
        throw new GroupAlreadyExistsException("Group: " + groupName + " already exists");
    } catch (ExecutionException e) {
        if (e.getCause() instanceof GroupNotFoundException) {
            try {
                Group group = addGroupToDB(groupName);
                updateGroupCache(group.getId(), group.getName());
            } catch (UniqueKeyConstraintViolationException ue) {
                throw new GroupAlreadyExistsException("Group: " + groupName + " already exists");
            }
        } else {
            throw new IOException(e);
        }
    }
    return getGroupId(groupName);
}

From source file:io.hops.security.UsersGroupsCache.java

public void removeUserFromGroup(String user, String group) throws IOException {

    if (user == null || group == null)
        return;/*from   w  ww  . j  a v a2 s.  c o m*/

    LOG.debug("Remove user-group from DB user: " + user + ", group: " + group);
    try {

        int userId = userToIdCache.get(user);
        int groupId = groupToIdCache.get(group);

        removeUserFromGroupDB(userId, groupId);

        invCachesUserRemovedFromGroup(user, group);

    } catch (ExecutionException e) {
        if (e.getCause() instanceof UserNotFoundException || e.getCause() instanceof GroupNotFoundException) {
            throw (IOException) e.getCause();
        } else {
            throw new IOException(e);
        }
    }
}

From source file:io.hops.security.UsersGroupsCache.java

public Integer addUser(String userName) throws IOException {

    if (userName == null) {
        return null;
    }/*from  ww  w  . j av  a 2  s .c om*/

    try {
        int id = userToIdCache.get(userName);
        throw new UserAlreadyExistsException("User: " + userName + " already exists with ID: " + id);
    } catch (ExecutionException e) {
        if (e.getCause() instanceof UserNotFoundException) {
            try {
                User user = addUserToDB(userName);
                updateUserCache(user.getId(), user.getName());
            } catch (UniqueKeyConstraintViolationException ue) {
                throw new UserAlreadyExistsException("User: " + userName + " already exists.");
            }
        } else {
            throw new IOException(e);
        }
    }

    return getUserId(userName);
}

From source file:org.apache.hadoop.hbase.regionserver.wal.AbstractFSWAL.java

protected Span blockOnSync(final SyncFuture syncFuture) throws IOException {
    // Now we have published the ringbuffer, halt the current thread until we get an answer back.
    try {/*from   www  .  j a v a  2s  .co  m*/
        syncFuture.get();
        return syncFuture.getSpan();
    } catch (InterruptedException ie) {
        LOG.warn("Interrupted", ie);
        throw convertInterruptedExceptionToIOException(ie);
    } catch (ExecutionException e) {
        throw ensureIOException(e.getCause());
    }
}

From source file:io.hops.security.UsersGroupsCache.java

public void addUserToGroup(String user, String group) throws IOException {
    assert user != null && group != null;

    LOG.debug("Adding user: " + user + " to Group: " + group);

    List<String> availableGroups = Collections.EMPTY_LIST;
    try {/*  w  w w  .j a  v  a  2  s  . com*/
        availableGroups = userToGroupsCache.get(user);
    } catch (ExecutionException e) {
        if (e.getCause() instanceof GroupsNotFoundForUserException) {
            // ok, continue
        } else {
            throw new IOException(e);
        }
    }

    if (availableGroups.contains(group)) {
        throw new UserAlreadyInGroupException("User: " + user + " is already part of Group: " + group + ".");
    }

    try {

        int userID = userToIdCache.get(user);
        int groupID = groupToIdCache.get(group);

        addUserToGroupDB(userID, groupID);

        invCacheUserAddedToGroup(user, group);

    } catch (ExecutionException e) {
        if (e.getCause() instanceof UserNotFoundException || e.getCause() instanceof GroupNotFoundException) {
            throw (IOException) e.getCause();
        } else {
            throw new IOException(e);
        }
    }
}