Add remove method to StateProviderInterface

This commit is contained in:
2023-10-16 08:28:00 -05:00
parent 61a6c0e8b0
commit 8102dbc8b2
3 changed files with 33 additions and 0 deletions

View File

@ -90,4 +90,15 @@ public class InMemoryStateProvider implements StateProviderInterface
}
}
/*******************************************************************************
** Remove a block of data, under a key, from the state store.
*******************************************************************************/
@Override
public void remove(AbstractStateKey key)
{
map.remove(key);
}
}

View File

@ -52,4 +52,10 @@ public interface StateProviderInterface
** Get a block of data, under a key, from the state store.
*******************************************************************************/
<T extends Serializable> Optional<T> get(Class<? extends T> type, AbstractStateKey key);
/*******************************************************************************
** Remove a block of data, under a key, from the state store.
*******************************************************************************/
void remove(AbstractStateKey key);
}

View File

@ -30,6 +30,7 @@ import java.util.Optional;
import com.kingsrook.qqq.backend.core.logging.QLogger;
import com.kingsrook.qqq.backend.core.utils.JsonUtils;
import org.apache.commons.io.FileUtils;
import static com.kingsrook.qqq.backend.core.logging.LogUtils.logPair;
/*******************************************************************************
@ -110,6 +111,21 @@ public class TempFileStateProvider implements StateProviderInterface
/*******************************************************************************
** Remove a block of data, under a key, from the state store.
*******************************************************************************/
@Override
public void remove(AbstractStateKey key)
{
File file = getFile(key);
if(!file.delete())
{
LOG.warn("Error deleting state-providing tempFile", logPair("file", file.getAbsolutePath()));
}
}
/*******************************************************************************
** Get the file referenced by a key
*******************************************************************************/